[Typescript 5.3] Switch true statement for type narrowing
class Fish {
swim(): void {}
}
class Bird {
fly(): void {}
}
switch(true) {
case val instanceof Bird:
val.fly()
break
case val instanceof Fish:
val.swim()
break
}
switch(true): means that it will validate each case, until it finds first when validated as true

浙公网安备 33010602011771号