-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
proposal:rest infer #26246
Comments
For anyone who needs a workaround for this today, you can use function types and TypeScript 3.0 rest tuples: type Tail<T extends any[]> = ((...args: T) => any) extends ((head: any, ...tail: infer U) => any) ? U : never; |
I did not know how to solve it Is this correct? type ToObj<T extends any[]> = ((...args: T) => any) extends ((head: infer X, ...tail: infer XS) => any) ? { x: X, xs: ToObj<XS> } : [];
type Foo = ToObj<[1, 2, 3, 4, 5]>;//{x: 1;xs: any;} |
Duplicate of #25719 ? Or are you trying to create a union of all items? Then it's just type UnionOf<T extends any[]> = T[number];
type Foo = UnionOf<[1,2,3]>; // 1 | 2 | 3 |
It's not clear what problem you're trying to solve here. The suggestion template has many more fields and it'd be great if you could fill them in completely -- just showing some syntax you'd expect to work doesn't give us enough context on what you'd like to happen, how you'd expect it to work, or reasons why this would be a good addition to the language. Thanks! |
Close this issue because it is a duplicate |
Search Terms
Generics
Suggestion
Decomposition of tuple type
Examples
There is a problem of #14174
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: