Type Challenges Judge

Tuple to Nested Object

提出詳細

type TupleToNestedObject<T extends readonly unknown[], U> = T extends [infer Head extends PropertyKey, ...infer Rest] ? {[P in Head]: TupleToNestedObject<Rest, U> } : U
提出日時2025-09-16 15:43:35
問題Tuple to Nested Object
ユーザーbalckowl
ステータス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>>, ]