-
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
Make tuples have known length #17765
Make tuples have known length #17765
Conversation
Shouldn't the |
practically it doesn't have to be, consider: interface X { length: 0; } |
It hadn't occurred to me; |
I'd probably add Note that for dumb reasons, |
tuple-array assignability blocked by microsoft#17765
fa530ff
to
1f77317
Compare
strictTuples
flag giving tuples known length
Update: should be good now, ready for feedback. |
Travis randomly complaining:
|
Tests should be fixed by ivogabe/gulp-typescript#536. |
Merged for retry, Travis seems good again. Thanks @ikatyang. |
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 like this change, but I'm going to try implementing tuple-freshness first to see if it works well too.
src/compiler/checker.ts
Outdated
if (strictTuples) { | ||
const lengthSymbol = createSymbol(SymbolFlags.Property, "length" as __String); | ||
lengthSymbol.type = getLiteralType(arity); | ||
lengthSymbol.checkFlags = CheckFlags.Readonly; |
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 don't see how adding Readonly helps if the type is literally 2
, because only 2
can be assigned to it. If the intent is future-proofing in case Readonly will someday propagate through assignments, I think that it's as likely to harm as it is to help.
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.
Yeah, fair enough. I had no special intentions in adding it. Feel free to adjust as you see fit! :)
Given that the total impact of this change is 3 good breaks (firebase, leaflet and highcharts), plus incorrect array syntax (9), I think that it is small enough to ship without a flag. |
We had one more meeting, and decided to ship this PR without a flag and without |
Thanks @tycho01! |
@sandersn please add a note about this change in the breaking change section for TS 2.7. We need also some guidance for the firebase use case |
Hooray! |
strictTuples
flag giving tuples known length
Thanks for the merge! At this rate I may get the motivation to finish those last few PRs too. :) |
This should be added to the January release notes roadmap. |
@michaeljota I added it to the roadmap. |
Add fixed
length
for tuples following @Aleksey-Bykov's a suggestion in #13239.Fixes #6229, so
[number, number]
would not match[number]
(length
2
wouldn't match1
).I put this behind a
strictTuples
flag so people can also still use the old behavior.