We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
TypeScript Version: 3.1.0-dev.20180727
Search Terms: tuple rest
Code
declare let tuple: [string, number, boolean]; let [a, ...rest] = tuple;
Expected behavior:
rest is of type [number, boolean];
rest
[number, boolean]
Actual behavior:
rest is inferred as (number | boolean)[] which loses type information.
(number | boolean)[]
Note that the behavior in @next is a bit better than 2.9.1, as it was (string | number | boolean)[] back then.
@next
(string | number | boolean)[]
Playground Link: https://agentcooper.github.io/typescript-play/?target=5#code/CYUwxgNghgTiAEEQBd7IK4AckC54G0BnZGASwDsBzAGnnPQFsAjEGWpgew6SnIF0A3ACgkqfFFoA6aUzB94AXjRYkAoA
Related Issues: #21519
When #6275 is fixed these two variants should have the same inference (although I don't know why someone would write something like that):
declare let tuple: [string, number, boolean]; let [a, b, c] = tuple; // or let [a, ...[b, ...{0: c}]] = tuple;
The text was updated successfully, but these errors were encountered:
Infer array rest as tuple if possible
090326b
Fixes: microsoft#26007
No branches or pull requests
TypeScript Version: 3.1.0-dev.20180727
Search Terms: tuple rest
Code
Expected behavior:
rest
is of type[number, boolean]
;Actual behavior:
rest
is inferred as(number | boolean)[]
which loses type information.Note that the behavior in
@next
is a bit better than 2.9.1, as it was(string | number | boolean)[]
back then.Playground Link: https://agentcooper.github.io/typescript-play/?target=5#code/CYUwxgNghgTiAEEQBd7IK4AckC54G0BnZGASwDsBzAGnnPQFsAjEGWpgew6SnIF0A3ACgkqfFFoA6aUzB94AXjRYkAoA
Related Issues:
#21519
When #6275 is fixed these two variants should have the same inference (although I don't know why someone would write something like that):
The text was updated successfully, but these errors were encountered: