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