00090-hard-optional-keys
Hard
utils

チャレンジのソース: type-challenges/00090-hard-optional-keys

オプショナルなキーの Union を抽出する高度なユーティリティ型 OptionalKeys<T> を実装してください。

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