Tuple to Nested Object
提出詳細
type TupleToNestedObject<T, U> = T extends [infer T1, ...infer T2] ? { [K in T1 & string]: TupleToNestedObject<T2,U> } : U
提出日時 | 2023-09-15 14:09:51 |
---|---|
問題 | Tuple to Nested Object |
ユーザー | sankantsu |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<TupleToNestedObject<['a'], string>, { a: string }>>, Expect<Equal<TupleToNestedObject<['a', 'b'], number>, { a: { b: number } }>>, Expect<Equal<TupleToNestedObject<['a', 'b', 'c'], boolean>, { a: { b: { c: boolean } } }>>, Expect<Equal<TupleToNestedObject<[], boolean>, boolean>>, ]