I'm using asserts condition and have a code like this
enum Types { a = "a", b = "b", c = "c" }
type Entity = { type: Types };
assert(condition: any): asserts condition {
if(!condition) throw new Error();
}
function abc(entity: Entity) {
assert(entity.type === Types.a || entity.type === Types.b);
...
}
function def(entity: Entity) {
assert(entity.type === Types.b || entity.type === Types.c);
...
}
function ghi(entity: Entity) {
assert(entity.type === Types.c);
...
}
Is it possible to make compact generic assertion function to use like this and get the same assertion type checks?
assertType(entity, [Types.a, Types.b]);
Answers to this question gave me an idea of solution.