Type Challenges Judge

Optional Keys

提出詳細

type OptionalKeys<T extends object> = keyof { [P in keyof T as {} extends Pick<T, P> ? P:never]: T[P]; };
提出日時2022-07-01 00:14:32
問題Optional Keys
ユーザーwaki285
ステータス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>>, ]