Type Challenges Judge

Required Keys

提出詳細

type IsRequired<T, K extends PropertyKey> = Omit<T, K> extends T ? false : true type GetRequiredKeys<K extends PropertyKey, T> = K extends any ? IsRequired<T, K> extends true ? K : never : never; type RequiredKeys<T> = GetRequiredKeys<keyof T, T>
提出日時2023-08-13 12:26:45
問題Required Keys
ユーザーtekihei2317
ステータスAccepted
テストケース
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<RequiredKeys<{ a: number; b?: string }>, 'a'>>, Expect<Equal<RequiredKeys<{ a: undefined; b?: undefined }>, 'a'>>, Expect<Equal<RequiredKeys<{ a: undefined; b?: undefined; c: string; d: null }>, 'a' | 'c' | 'd'>>, Expect<Equal<RequiredKeys<{}>, never>>, ]