-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Open
Description
533 - Concat
Concat is the first in a series of challenges that look at common array manipulation techniques. There are many more to come, but it starts out small with this challenge.
🎥 Video Explanation
🔢 Code
import type { Equal, Expect } from './test-utils'
type A1 = Concat<[], []>;
type B1 = [];
type C1 = Expect<Equal<A1, B1>>;
type A2 = Concat<[], [1]>;
type B2 = [1];
type C2 = Expect<Equal<A2, B2>>;
type A3 = Concat<[1, 2], [3, 4]>;
type B3 = [1, 2, 3, 4];
type C3 = Expect<Equal<A3, B3>>;
type A4 = Concat<['1', 2], [false, boolean, '4']>;
type B4 = ['1', 2, false, boolean, '4'];
type C4 = Expect<Equal<A4, B4>>;
// ============= Your Code Here =============
type Concat<
T extends unknown[],
U extends unknown[]
> = [...T, ...U];
// ============== Alternatives ==============
// this is bad
// because it won't error if you pass a non-array
type Concat<T, U> =
T extends unknown[]
? U extends unknown[]
? [...T, ...U]
: never
: never;
➕ More Solutions
For more video solutions to other challenges: see the umbrella list! #21338
Metadata
Metadata
Assignees
Labels
No labels