Type Challenges Judge

RequiredByKeys

提出詳細

type Merge<F,S,X=Omit<F,keyof S> & S> = { [ K in keyof X ]: X[K] } type RequiredKeyOnly<T,Key> = { [ K in keyof T as K extends Key ? K : never]-?: T[K] } type RequiredByKeys<T,Key extends keyof T=keyof T> = Merge<Partial<T>,RequiredKeyOnly<T,Key>>
提出日時2023-09-15 13:40:27
問題RequiredByKeys
ユーザーsankantsu
ステータスWrong Answer
テストケース
import type { Equal, Expect } from '@type-challenges/utils' interface User { name?: string age?: number address?: string } interface UserRequiredName { name: string age?: number address?: string } interface UserRequiredNameAndAge { name: string age: number address?: string } type cases = [ Expect<Equal<RequiredByKeys<User, 'name'>, UserRequiredName>>, Expect<Equal<RequiredByKeys<User, 'name' | 'unknown'>, UserRequiredName>>, Expect<Equal<RequiredByKeys<User, 'name' | 'age'>, UserRequiredNameAndAge>>, Expect<Equal<RequiredByKeys<User>, Required<User>>>, ]