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

In JS Class serialization, read the base construct signature from the static base type #41767

Conversation

weswigham
Copy link
Member

And not the instance base type, where non-static members come from.

Fixes #41397

@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Dec 1, 2020
/**
* @param {U} param
*/
constructor(param: U);
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

@weswigham weswigham Dec 2, 2020

Choose a reason for hiding this comment

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

It's identical to the base signature (the base signature is instantiated into the same signature as in the sub class), and thus redundant.

Copy link
Member

Choose a reason for hiding this comment

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

Interesting.. i thought that would be elided only if O had elided it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nah - the node serializer looks at semantic information usually, not syntactic. Sometimes we reuse input type nodes where possible, but generally not wholesale signature declarations like this. So since the class only has one signature, and it's identical to the signature provided by the base class, we "elide" it so as to not include the base class's signature in all subclasses, since we don't need it.

@weswigham weswigham merged commit 9f9eed4 into microsoft:master Dec 2, 2020
@weswigham weswigham deleted the fix-jsdoc-decl-class-construct-signature branch December 2, 2020 21:33
@@ -6772,7 +6772,7 @@ namespace ts {
!some(getSignaturesOfType(staticType, SignatureKind.Construct));
const constructors = isNonConstructableClassLikeInJsFile ?
[factory.createConstructorDeclaration(/*decorators*/ undefined, factory.createModifiersFromModifierFlags(ModifierFlags.Private), [], /*body*/ undefined)] :
serializeSignatures(SignatureKind.Construct, staticType, baseTypes[0], SyntaxKind.Constructor) as ConstructorDeclaration[];
serializeSignatures(SignatureKind.Construct, staticType, staticBaseType, SyntaxKind.Constructor) as ConstructorDeclaration[];
Copy link
Contributor

Choose a reason for hiding this comment

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

I love the subtlety of this fix and I keep on being amazed that DevTools "fuzzes" TypeScript 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSDoc generated declaration omits constructor of child class
5 participants