PartialByKeys
提出詳細
type Merge<F,S,X=Omit<F,keyof S> & S> = { [ K in keyof X ]: X[K] } type PartialKeyOnly<T,Key> = { [ K in keyof T as K extends Key ? K : never]?: T[K] } type PartialByKeys<T,Key=keyof T> = Merge<T,PartialKeyOnly<T,Key>>
提出日時 | 2023-09-15 13:34:09 |
---|---|
問題 | PartialByKeys |
ユーザー | sankantsu |
ステータス | 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>>>, ]