ObjectFromEntries
提出詳細
type UnionToIntersection<U> = ( U extends unknown ? (arg: U) => 0 : never ) extends (arg: infer I) => 0 ? I : never; type LastInUnion<U> = UnionToIntersection< U extends unknown ? (x: U) => 0 : never > extends (x: infer L) => 0 ? L : never; type UnionToTuple<U, Last = LastInUnion<U>> = [U] extends [never] ? [] : [...UnionToTuple<Exclude<U, Last>>, Last]; type FromEntries<T> = T extends unknown[][] ? { [P in T[number]as P[0] extends PropertyKey ? P[0] : never]: P[1] } : never type ObjectFromEntries<T> = FromEntries<UnionToTuple<T>>
提出日時 | 2024-09-12 15:14:52 |
---|---|
問題 | ObjectFromEntries |
ユーザー | ookkoouu |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' interface Model { name: string age: number locations: string[] | null } type ModelEntries = ['name', string] | ['age', number] | ['locations', string[] | null] type cases = [ Expect<Equal<ObjectFromEntries<ModelEntries>, Model>>, ]