Open kscory opened 5 months ago
type Flatten<T extends unknown[], Result extends unknown[] = []> = T extends [infer F, ...infer S]
? F extends [...infer U]
? Flatten<[...Flatten<U>, ...S], Result>
: Flatten<S, [...Result, F]>
: Result;
아래가 더 나은 정답 같네요
type Flatten<T extends unknown[]> = T extends [infer F, ...infer S]
? F extends unknown[]
? [...Flatten<[...F, ...S]>]
: [F, ...Flatten<S>]
: [];
type Flatten<T extends any[],U extends any[] =[]> = T extends [infer X , ...infer Y] ?
X extends any[]?
Flatten<[...X,...Y],U> :Flatten<[...Y], [...U, X]>
: U
아래가 더 나은 정답 같네요
type Flatten<T extends unknown[]> = T extends [infer F, ...infer S] ? F extends unknown[] ? [...Flatten<[...F, ...S]>] : [F, ...Flatten<S>] : [];
와 이렇게 보니까 간단하네 ..
type Flatten<T extends any[]> = T extends [infer A, ...infer B]
? A extends any[]
? [...Flatten<[...A, ...B]>]
: [A, ...Flatten<B>]
: [];
답안을 작성해주세요.