Type Challenges Judge

Tuple to Nested Object

提出詳細

type TupleToNestedObject<T extends unknown[], U> = T extends [infer F extends PropertyKey, ...infer R] ? R["length"] extends 0 ? { [P in F]: U } : { [P in F]: TupleToNestedObject<R, U> } : U
提出日時2023-08-31 10:31:23
問題Tuple to Nested Object
ユーザーookkoouu
ステータス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>>, ]