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