typescript check if type code example
Example 1: typescript check type of variable
if (fooOrBar instanceof Foo){
// TypeScript now knows that `fooOrBar` is `Foo`
}
Example 2: typescript check type
mySprite instanceof Sprite;
if (fooOrBar instanceof Foo){
// TypeScript now knows that `fooOrBar` is `Foo`
}
mySprite instanceof Sprite;