Type Challenges Judge

Get Optional

提出詳細

type IsOptional<T, K extends PropertyKey> = Omit<T, K> extends T ? true : false type GetOptional<T> = { [K in keyof T as IsOptional<T, K> extends true ? K : never]: T[K] }
提出日時2023-08-13 12:16:45
問題Get Optional
ユーザーtekihei2317
ステータスAccepted
テストケース
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 }>>, ]