Is there a way in typescript to define a type which accepts anything except for a few things?
Consider this snippet:
type BagGuys = 'Voldemort' | 'Hitler';
type EveryoneElse = Exclude<string, BagGuys>; // this resolves to just string
function sayHi(name: EveryoneElse) {
console.log(`Hi ${name}!`);
}
sayHi('Mark'); // Ok!
sayHi('Voldemort'); // Ok too, we'd like to have an error here
I, of course, would like typescript to prevent me from saying hi to the bad guys.
Note: I understand why Exclude doesn't work here, I'm just using it to convey my intention