Type Challenges Judge

Get Required

提出詳細

type MyEqual<T,U> = (<X>() => X extends T ? 0 : 1) extends (<X>() => X extends U ? 0 : 1) ? true : false type GetRequired<T,U=Required<T>> = { [K in keyof T as K extends keyof U ? MyEqual<T[K],U[K]> extends true ? K : never : never ]: T[K] }
提出日時2023-09-19 04:00:33
問題Get Required
ユーザーsankantsu
ステータスAccepted
テストケース
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<GetRequired<{ foo: number; bar?: string }>, { foo: number }>>, Expect<Equal<GetRequired<{ foo: undefined; bar?: undefined }>, { foo: undefined }>>, ]