π« Exclude<T, U>
Exclude<T, U> creates a new union type by removing specific types from an existing union.
πΉ Example
type Role = "admin" | "user" | "guest";
type PublicRole = Exclude<Role, "admin">;
const role: PublicRole = "user"; // β
Now PublicRole becomes:
"user" | "guest"So this is not allowed:
const role: PublicRole = "admin"; // β Errorπ‘ Common Use
Exclude is useful when you have a union type but want to remove certain options from it.
Remember:
Exclude<T, U>β RemovesUfrom the unionT.