Skip to content

Latest commit

 

History

History
30 lines (22 loc) · 1 KB

README.md

File metadata and controls

30 lines (22 loc) · 1 KB

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">;

⚠️ Limitations:

  • StrictOmit cannot be used when Type is generic type – ts-essentials#343 (please use Omit instead)

TS Playground – https://tsplay.dev/N9jPjm