TypeScript nicety. A variable's type is a union of classes:
declare const aorb: A | B
You want to handle each class separately with a sequence like
if (aorb instanceof A) { }
else if (aorb instanceof B) { }
You also want to be sure that if another class is added you don't forget to amend the if-cascade. Just add:
else { throw aorb satisfies never; }
Full code on playground. Can this be done with switch too?