From T
, pick a set of properties whose type are not assignable to U
.
For Example
type OmitBoolean = OmitByType<{
name: string
count: number
isReadonly: boolean
isEnable: boolean
}, boolean> // { name: string; count: number }
/* _____________ Your Code Here _____________ */
type OmitByType<T extends object, U> = {
[Key in keyof T as T[Key] extends U ? never: Key]: T[Key]
}
/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'
interface Model {
name: string
count: number
isReadonly: boolean
isEnable: boolean
}
type cases = [
Expect<Equal<OmitByType<Model, boolean>, { name: string; count: number }>>,
Expect<Equal<OmitByType<Model, string>, { count: number; isReadonly: boolean; isEnable: boolean }>>,
Expect<Equal<OmitByType<Model, number>, { name: string; isReadonly: boolean; isEnable: boolean }>>,
]
标签:Typescript,Key,_____________,51,number,boolean,Medium,OmitByType,type From: https://www.cnblogs.com/Answer1215/p/16796535.html