Tuple to Object
提出詳細
type TupleToObject<T extends readonly (string | number)[] > = { [k in T[number]] :k};
提出日時 | 2023-12-12 09:43:05 |
---|---|
問題 | Tuple to Object |
ユーザー | okajima-hirotada |
ステータス | Accepted |
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], {}]>