StrictOmit<Type, Keys>
constructs a type by picking all properties from Type
and then removing Keys
interface CatInfo {
age: number;
breed: string;
}
type CatInfoWithoutBreed = StrictOmit<CatInfo, "breed">;
// ^? { age: number }
This is stricter version of Omit
,
meaning StrictOmit
validates that properties Keys
exist in type Type
// error: Type '"height"' does not satisfy the constraint 'keyof CatInfo'
type CatInfoWithoutHeight = StrictOmit<CatInfo, "height">;
// error: Type '"age" | "weight"' does not satisfy the constraint 'keyof CatInfo'
// Type '"weight"' is not assignable to type 'keyof CatInfo'
type CatInfoWithoutAgeAndWeight = StrictOmit<CatInfo, "age" | "weight">;
StrictOmit
cannot be used whenType
is generic type – ts-essentials#343 (please useOmit
instead)
TS Playground – https://tsplay.dev/N9jPjm