Edit: Remove indexing part
Edit 2: Replace tuple mapping syntax with normal mapped types
Search Terms
Concatentate and merge tuples' entries.
Suggestion
- I would like to be able to extract and spread in positions other than the last part of a tuple.
- I would like to merge a tuple into an intersection or concatenation of its members.
Use Cases
- Converting a tuple to its intersection, such as with
Object.assign's assignee. - Typing
Array.prototype.concat correctly for tuples.
Syntax
The syntax comes in a few new forms:
[...A, B] appends B to the tuple A. Similarly, [...infer A, any] extends B ? A : [] drops the last item of the tuple and [...any[], infer A] extends B ? A : never extracts the first.{... ...T} for an n-ary merge and [... ...T] an n-ary concatenation.
Examples
Here's the types for each method I mentioned above.
interfaceArray<T>{concat<Uextendsany[]>(...others: U): [...this, ... ...{[IinkeyofU]: (U[I]extendsany[] ? N : U[I]extendsArrayLike<infer R> ? R[] : [U[I]])}];}interfaceObjectConstructor{assign(target: {... ...typeofsources}, ...sources: object[]): typeoftarget;}Checklist
My suggestion meets these guidelines:
Edit: Remove indexing part
Edit 2: Replace tuple mapping syntax with normal mapped types
Search Terms
Concatentate and merge tuples' entries.
Suggestion
Use Cases
Object.assign's assignee.Array.prototype.concatcorrectly for tuples.Syntax
The syntax comes in a few new forms:
[...A, B]appendsBto the tupleA. Similarly,[...infer A, any] extends B ? A : []drops the last item of the tuple and[...any[], infer A] extends B ? A : neverextracts the first.{... ...T}for an n-ary merge and[... ...T]an n-ary concatenation.Examples
Here's the types for each method I mentioned above.
Checklist
My suggestion meets these guidelines: