Type Challenges Judge

Optional Keys

提出詳細

type OptionalKeys<T> = keyof { [K in keyof T as {} extends Pick<T, K> ? K : never]: any; }
提出日時2023-08-13 12:35:24
問題Optional Keys
ユーザーtekihei2317
ステータス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>>, ]