Flatten
提出詳細
type Flatten<T extends unknown[], Res extends unknown[] = []> = T extends [infer F, ...infer R] ? R["length"] extends 0 ? F extends unknown[] ? [...Res, ...Flatten<F>] : [...Res, F] : F extends unknown[] ? Flatten<R, [...Res, ...Flatten<F>]> : Flatten<R, [...Res, F]> : Res
提出日時 | 2023-08-30 09:24:28 |
---|---|
問題 | Flatten |
ユーザー | ookkoouu |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<Flatten<[]>, []>>, Expect<Equal<Flatten<[1, 2, 3, 4]>, [1, 2, 3, 4]>>, Expect<Equal<Flatten<[1, [2]]>, [1, 2]>>, Expect<Equal<Flatten<[1, 2, [3, 4], [[[5]]]]>, [1, 2, 3, 4, 5]>>, Expect<Equal<Flatten<[{ foo: 'bar'; 2: 10 }, 'foobar']>, [{ foo: 'bar'; 2: 10 }, 'foobar']>>, ]