Skip to content

Latest commit

 

History

History

strict-exclude

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

StrictExclude<UnionType, ExcludedMembers> constructs a type by excluding from UnionType all union members that are assignable to ExcludedMembers

type CatName = "miffy" | "boris" | "mordred";

type MiffyAndBoris = StrictExclude<CatName, "mordred">;
//   ^? "miffy" | "boris"

This is stricter version of Exclude, meaning StrictExclude validates that all ExcludedMembers union members are assignable to type UnionType

// error: Type '"Norris"' does not satisfy the constraint 'CatName'
type NotMrsNorris = StrictExclude<CatName, "Norris">;
//                                         ^^^^^^^^

// error: Type '"mordred" | "Norris"' does not satisfy the constraint 'CatName'.
//   Type '"Norris"' is not assignable to type 'CatName'
type NotMordredOrMrsNorris = StrictExclude<CatName, "mordred" | "Norris">;
//                                                  ^^^^^^^^^^^^^^^^^^^^

⚠️ Limitations:

  • StrictExclude cannot be used when UnionType is generic type – #343 (please use Exclude instead)

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