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

Tuple suffix associated with rest element in a binding pattern #2714

Closed
JsonFreeman opened this issue Apr 10, 2015 · 1 comment
Closed

Tuple suffix associated with rest element in a binding pattern #2714

JsonFreeman opened this issue Apr 10, 2015 · 1 comment
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead Suggestion An idea for TypeScript

Comments

@JsonFreeman
Copy link
Contributor

You could imagine that someone had the following:

var tuple: [string, number] = ["", 0];
var [a, ...b] = tuple;

Right now, a is string, but b is (string | number)[]. This is because the type associated with b is the array of the element type of the incoming array.

But it would be really nice if b was [number], or at least number[]. You should be able to chop off the rest of the elements in the incoming array, and only use those for the type associated with a rest element.

@JsonFreeman JsonFreeman added Suggestion An idea for TypeScript Spec Issues related to the TypeScript language specification In Discussion Not yet reached consensus labels Apr 10, 2015
@RyanCavanaugh RyanCavanaugh added By Design Deprecated - use "Working as Intended" or "Design Limitation" instead and removed In Discussion Not yet reached consensus Spec Issues related to the TypeScript language specification labels May 19, 2015
@RyanCavanaugh
Copy link
Member

The idea as I understand it is that any spread operator assumes that "all of the rest of the values" are in the domain of the tuple-specified types.

e.g.

var tuple: [string, number] = ["", 0];
tuple.push(42); // ok
tuple.push('hello'); // ok
tuple.push(window); // err
var [a, ...b] = tuple; // desired: b: Array<string|number>

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants