Skip to content
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

BindingRestElement should be inferred as tuple if possible #26007

Closed
ajafff opened this issue Jul 27, 2018 · 0 comments
Closed

BindingRestElement should be inferred as tuple if possible #26007

ajafff opened this issue Jul 27, 2018 · 0 comments
Labels
Help Wanted You can do this Suggestion An idea for TypeScript

Comments

@ajafff
Copy link
Contributor

ajafff commented Jul 27, 2018

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];

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):

declare let tuple: [string, number, boolean];

let [a, b, c] = tuple;
// or
let [a, ...[b, ...{0: c}]] = tuple;
@mhegazy mhegazy added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Jul 27, 2018
ajafff added a commit to ajafff/TypeScript that referenced this issue Jul 30, 2018
@RyanCavanaugh RyanCavanaugh added Help Wanted You can do this and removed In Discussion Not yet reached consensus labels Sep 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants