Type alias ConcatTuple<A, B>

ConcatTuple<A, B>: [...A, ...B]

Concatenate two tuple.

Type Parameters

  • A extends AnyArray

  • B extends AnyArray

Remarks

This type should always be used when concatenating 2 tuples.

In the current version of Typescript (4.8.4), tuple's members have labels, but there is no accessor to those labels. We often want to preserve the labels (the most used case is for the argument named of a function), while transforming the tuple. But most of the times, type transformation does not preserve the label.

Example

type MyCoolTuple = [x: number, y: string];
type UnnamedTuple = [...MyCoolTuple, boolean];
type NamedTuple = [...MyCoolTuple, ...[z: boolean]];

// type NonExample = [...MyCoolTuple, z: boolean];

Here, UnNamedTuple will be [number, string, boolean], while NamedTuple will be [x: number, y: string, z: boolean].

Link to the playground is here

Another reason to use this type, is for type-safety, as we force the usage of the tuple.

Generated using TypeDoc