Type Challenges Judge

Required Keys

提出詳細

type RequiredKeys<T,U=Required<T>,K extends keyof T=keyof T> = K extends keyof U ? T[K] extends U[K] ? K : never : never
提出日時2023-09-22 15:42:17
問題Required Keys
ユーザーsankantsu
ステータス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>>, ]