PartialByKeys
提出詳細
type Pretty<T> = { [K in keyof T]: T[K] } type PartialByKeys<T, K = keyof T> = Pretty<{ [P in keyof T as P extends K ? P : never]?: T[P] } & { [P in Exclude<keyof T, K>]: T[P] }>
提出日時 | 2023-08-13 09:33:01 |
---|---|
問題 | PartialByKeys |
ユーザー | tekihei2317 |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' interface User { name: string age: number address: string } interface UserPartialName { name?: string age: number address: string } interface UserPartialNameAndAge { name?: string age?: number address: string } type cases = [ Expect<Equal<PartialByKeys<User, 'name'>, UserPartialName>>, Expect<Equal<PartialByKeys<User, 'name' | 'unknown'>, UserPartialName>>, Expect<Equal<PartialByKeys<User, 'name' | 'age'>, UserPartialNameAndAge>>, Expect<Equal<PartialByKeys<User>, Partial<User>>>, ]