Type Challenges Judge

ObjectEntries

提出詳細

type NeverToUndefined<T> = [T] extends [never] ? undefined : T type Helper<T,K extends keyof T=keyof T> = K extends K ? [K,NeverToUndefined<T[K]>] : never type ObjectEntries<T> = Helper<Required<T>>
提出日時2023-09-15 13:59:46
問題ObjectEntries
ユーザーsankantsu
ステータス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<ObjectEntries<Model>, ModelEntries>>, Expect<Equal<ObjectEntries<Partial<Model>>, ModelEntries>>, Expect<Equal<ObjectEntries<{ key?: undefined }>, ['key', undefined]>>, Expect<Equal<ObjectEntries<{ key: undefined }>, ['key', undefined]>>, ]