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>>, ]