Skip to content
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

Merged
merged 4 commits into from
May 5, 2017

Conversation

sandersn
Copy link
Member

@sandersn sandersn commented May 2, 2017

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.

sandersn added 2 commits May 2, 2017 13:36
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.
const baseTypeNode = getClassExtendsHeritageClauseElement(node);
let tempVarName: string;
if (isNonNullExpression(baseTypeNode)) {
tempVarName = emitTempVariableDeclaration(baseTypeNode.expression, `_${node.name.text}_intersection_base`, {
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (!noDeclare) {
write("declare ");
}
write("var ");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider making this const

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -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)) {
Copy link
Contributor

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..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right! Removed.

@mhegazy
Copy link
Contributor

mhegazy commented May 5, 2017

@sandersn, does this also address #15572?

@mhegazy
Copy link
Contributor

mhegazy commented May 5, 2017

Please port the change to release-2.3 as well.

@sandersn sandersn merged commit 4303a29 into master May 5, 2017
@sandersn sandersn deleted the emit-declaration-of-class-extending-intersection branch May 5, 2017 15:33
@sandersn
Copy link
Member Author

sandersn commented May 5, 2017

It should fix #15572 since the error arises from incorrect flattening of an expression in extends. I'm testing it right now.

@sandersn
Copy link
Member Author

sandersn commented May 5, 2017

Yes, it fixes #15572. I also ported this change to 2.3

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants