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