how do you concat type types in typescript?

With recursive conditional types (TS 4.1.0), you’ll be able to:

type T1 = ['a', 'b', 'c']
type T2 = ['d', 'e', 'f']
type TN = [1, 2, 3]

type Concat<T> = T extends [infer A, ...infer Rest]
    ? A extends any[] ? [...A, ...Concat<Rest>] : A
    : T;

type C = Concat<[T1, T2, TN]>; // ["a", "b", "c", "d", "e", "f", 1, 2, 3]

Playground

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top