Type Challenges Judge

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>>, ]