If you want to exclude certain values from a predefined conditional type, you can easily achieve this by using the Exclude
method:
type Colors = 'red' | 'blue' | 'green';
type PrimaryColors = <b>Exclude</b><Colors, 'green'>;
const PrimaryColors = 'red';
It's worth noting that the following syntax works as well, even though it might seem odd initially:
type PrimaryColors = Exclude<Colors, 'yellow'>
Check out the example on the TypeScript playground for more clarity.
Furthermore, you can combine exclusion with index types to achieve interesting results:
type Colors = 'red' | 'blue' | 'green';
type ColorObject = { green: boolean }
type PrimaryColors = Exclude<Colors, keyof ColorObject>
const primaryColorVar: PrimaryColors = "red";