Type Challenges Judge

Optional Keys

提出詳細

type OptionalKeys<T> = keyof { [P in keyof T as Partial<Pick<T, P>> extends Pick<T, P> ? P : never]: T[P] }
提出日時2024-09-12 08:04:47
問題Optional Keys
ユーザーookkoouu
ステータスAccepted
テストケース
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<OptionalKeys<{ a: number; b?: string }>, 'b'>>, Expect<Equal<OptionalKeys<{ a: undefined; b?: undefined }>, 'b'>>, Expect<Equal<OptionalKeys<{ a: undefined; b?: undefined; c?: string; d?: null }>, 'b' | 'c' | 'd'>>, Expect<Equal<OptionalKeys<{}>, never>>, ]