Type Challenges Judge

Tuple to Object

提出詳細

/* _____________ Your Code Here _____________ */ type TupleToObject<T extends readonly string[]> = { [P in T[number]]: P } /* _____________ Test Cases _____________ */ import type { Equal, Expect } from '@type-challenges/utils' const tuple = ['tesla', 'model 3', 'model X', 'model Y'] as const type cases = [ Expect<Equal<TupleToObject<typeof tuple>, { tesla: 'tesla'; 'model 3': 'model 3'; 'model X': 'model X'; 'model Y': 'model Y' }>>, ] // @ts-expect-error type error = TupleToObject<[[1, 2], {}]> type Foo = TupleToObject<typeof tuple>
提出日時2024-02-13 08:11:27
問題Tuple to Object
ユーザーKatsukiniwa
ステータスJudging
テストケース
import type { Equal, Expect } from '@type-challenges/utils' const tuple = ['tesla', 'model 3', 'model X', 'model Y'] as const type cases = [ Expect<Equal<TupleToObject<typeof tuple>, { tesla: 'tesla'; 'model 3': 'model 3'; 'model X': 'model X'; 'model Y': 'model Y' }>>, ] // @ts-expect-error type error = TupleToObject<[[1, 2], {}]>