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. |
sandersn
left a comment
There was a problem hiding this comment.
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.
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.
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
lengthfor tuples following @Aleksey-Bykov's a suggestion in #13239.Fixes #6229, so
[number, number]would not match[number](length2wouldn't match1).I put this behind a
strictTuplesflag so people can also still use the old behavior.