-
Notifications
You must be signed in to change notification settings - Fork 12.8k
In JS, class supports @template
tag for declaring type parameters
#23511
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
Conversation
Still need to do the following: 1. Correctly get jsdoc host in predicate. 2. Make this work for constructor functions too. 3. Scan rest of codebase for other usages of the type parameters property that should be calls to getEffectiveTypeParameterDeclarations. 4. Rename tp to something more readable, like typar or ts'.
CI failed because I missed a fourslash test. It's updated now. |
I added support for |
src/compiler/checker.ts
Outdated
@@ -2060,10 +2061,10 @@ namespace ts { | |||
let symbol: Symbol; | |||
if (name.kind === SyntaxKind.Identifier) { | |||
const message = meaning === namespaceMeaning ? Diagnostics.Cannot_find_namespace_0 : Diagnostics.Cannot_find_name_0; | |||
|
|||
symbol = resolveName(location || name, name.escapedText, meaning, ignoreErrors ? undefined : message, name, /*isUse*/ true); | |||
const secondarySymbol = resolveEntityNameFromJSPrototype(name, meaning); |
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 adding isInJavascriptFile
just for clarity.
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.
And maybe a comment that says "secondarySymbol is undefined except for type references in jsdoc on javascript prototype assignments"
Or something simpler than that. Hopefully.
Previously, classes did not understand the
@template
tag, so there was no way to declare and use type parameters on classes in Javascript.This change makes the checker get the "effective" type parameters for a class, which means that Javascript classes also check their jsdoc for
@template
tags. The rest of the type parameter machinery is unchanged.Edit: this PR now makes type parameters work with constructor functions as well. This required changes in name resolution and class instantiation since type parameters can be looked up outside their scope, and the anonymous type created by newing a Javascript constructor can now be instantiated.
Only the class support is needed to unblock webpack/webpack#7046 and webpack/webpack#7050, however.
Fixes #23459
Fixes #23384
Fixes #23385
Fixes #18135