00059-hard-get-optional
Hard
utils
infer

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

オプショナルなフィールドのみを残す高度なユーティリティ型 GetOptional<T> を実装してください。

例えば

type I = GetOptional<{ foo: number, bar?: string }> // expected to be { bar?: string }

Loading...
import type { Equal, Expect } from '@type-challenges/utils'

type cases = [
  Expect<Equal<GetOptional<{ foo: number, bar?: string }>, { bar?: string }>>,
  Expect<Equal<GetOptional<{ foo: undefined, bar?: undefined }>, { bar?: undefined }>>,
]