Skip to content
Onsite

Concat<T, U>

EasyP3Coding

Implement Concat<T, U>, the type of two tuples joined into one, as the JavaScript expression [...T, ...U] would be. It must accept readonly tuples and reject non-arrays.

Tests your type must pass

const tuple = [1] as const

type cases = [
  Expect<Equal<Concat<[], []>, []>>,
  Expect<Equal<Concat<[], [1]>, [1]>>,
  Expect<Equal<Concat<typeof tuple, typeof tuple>, [1, 1]>>,
  Expect<Equal<Concat<[1, 2], [3, 4]>, [1, 2, 3, 4]>>,
  Expect<Equal<Concat<['1', 2, '3'], [false, boolean, '4']>, ['1', 2, '3', false, boolean, '4']>>,
]

// @ts-expect-error null is not a tuple
type error = Concat<null, undefined>

Hints

TypeScript
Run and Submit type-check your solution against the tests.