Flatten
提出詳細
type Helper<T> = T extends [infer U, ...infer V] ? [...Helper<U>, ...Flatten<V>] : [T] type Flatten<T extends readonly unknown[]> = T extends [infer U, ...infer V] ? [...Helper<U>, ...Flatten<V>] : []
提出日時 | 2023-09-14 02:57:10 |
---|---|
問題 | Flatten |
ユーザー | sankantsu |
ステータス | 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']>>, ]