RequiredByKeys
提出詳細
type RequiredByKeys<T, K = string> = Omit<{ [P in keyof T as P extends K ? P : never]-?: T[P] } & { [P in keyof T as P extends K ? never : P]: T[P] }, never>
提出日時 | 2024-09-11 11:03:57 |
---|---|
問題 | RequiredByKeys |
ユーザー | ookkoouu |
ステータス | Accepted |
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>>>, ]