-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Unify representation of tuples and other generic types #10466
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
Will this be developed into #5453 ? Synthesized generic types and tuple types looks much like variadic kinds. |
I quite like the changes in the error baselines. Feels neater. |
@@ -2214,6 +2211,11 @@ namespace ts { | |||
writePunctuation(writer, SyntaxKind.OpenBracketToken); | |||
writePunctuation(writer, SyntaxKind.CloseBracketToken); | |||
} | |||
else if (type.target.flags & TypeFlags.Tuple) { | |||
writePunctuation(writer, SyntaxKind.OpenBracketToken); | |||
writeTypeList(type.typeArguments.slice(0, getTypeReferenceArity(type)), SyntaxKind.CommaToken); |
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.
Why copy this list? Or are there extra type arguments that slice
omits? #Resolved
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.
When a generic type has a this
parameter other than itself it is represented as an extra type parameter.
👍 |
With this PR we unify the internal representation of tuple types and other generic types. Tuple types are now represented as regular type references to synthesized generic types of the form:
With these changes it is no longer necessary to special case tuple types throughout the type checker. All of the optimizations we have in place for regular generic type references now also apply to tuple types.
Fixes #10431. The compile time for the example drops from 1.2s to 0.08s with
--lib es5
and from 30.5s to 0.11s with--lib es6
.