-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emit declaration of class extending intersection #15537
Emit declaration of class extending intersection #15537
Conversation
Classes that extend expressions will get a synthetic var declaration for the expression. This is required for classes that extend an expression that return an intersection type.
src/compiler/declarationEmitter.ts
Outdated
const baseTypeNode = getClassExtendsHeritageClauseElement(node); | ||
let tempVarName: string; | ||
if (isNonNullExpression(baseTypeNode)) { | ||
tempVarName = emitTempVariableDeclaration(baseTypeNode.expression, `_${node.name.text}_intersection_base`, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would remove the _intersection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not think you need the leading "_" either
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/compiler/declarationEmitter.ts
Outdated
if (!noDeclare) { | ||
write("declare "); | ||
} | ||
write("var "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider making this const
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/compiler/checker.ts
Outdated
@@ -22645,7 +22645,7 @@ namespace ts { | |||
const classType = <InterfaceType>getDeclaredTypeOfSymbol(getSymbolOfNode(node)); | |||
resolveBaseTypesOfClass(classType); | |||
const baseType = classType.resolvedBaseTypes.length ? classType.resolvedBaseTypes[0] : unknownType; | |||
if (!baseType.symbol) { | |||
if (!baseType.symbol && !(baseType.flags & TypeFlags.Intersection)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should not be necessary here, right? we never call this function with an expression..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right! Removed.
Please port the change to release-2.3 as well. |
It should fix #15572 since the error arises from incorrect flattening of an expression in |
Yes, it fixes #15572. I also ported this change to 2.3 |
Classes that extend expressions will get a synthetic var declaration for
the expression. This is required for classes that extend an expression
that return an intersection type.
Fixes #14075, but not #15066, which is the full mixin scenario. You still can't export a class that inherits from a class expression that was returned from a function. That probably requires more complicated type declarations to be generated.