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