Type Challenges Judge

RequiredByKeys

提出詳細

type RequiredByKeys<T extends object, K extends keyof T> = { [P in Exclude<keyof T, K>]: T[P] } & { [P in K]: T[K] }
提出日時2024-10-29 06:58:53
問題RequiredByKeys
ユーザーbalckowl
ステータス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>>>, ]