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