-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Generic type aliases #3397
Generic type aliases #3397
Conversation
declaredType?: Type; // Type of class, interface, enum, or type parameter | ||
declaredType?: Type; // Type of class, interface, enum, type alias, or type parameter | ||
typeParameters?: TypeParameter[]; // Type parameters of type alias (empty array if none) | ||
instantiations?: Map<Type>; // Instantiations of generic type alias |
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.
Does it make sense to move the typeParameters
and instantiations
here for classes and interfaces as well? Seems like it would be nice if they were all in one place.
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 will think about it. It is generally more convenient to have them on the Type object because that's what we're operating on in most cases. Getting back to the SymbolLinks from the type requires us to do getSymbolLinks(type.symbol)
which adds a bit of overhead.
return unknownType; | ||
} | ||
if (node.typeArguments) { | ||
error(node, Diagnostics.Type_0_is_not_generic, symbolToString(symbol)); |
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.
Seems like this error check is being done in 3 places. Can they be consolidated into one check in getTypeFromTypeReference?
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.
Not easily since we fan out based on symbol kind and only during that processing figure out if the type requires type arguments or not. Best we could do is a helper we call in the 3 places, but it doesn't really seem to be worth it.
👍 |
Conflicts: src/compiler/checker.ts
…when using es6 bindings in typescript
With this PR type aliases can be generic. For example:
Fixes #1616.