In ActionScript, it is possible to check the type at run-time using the is operator:
var mySprite:Sprite = new Sprite();
trace(mySprite is Sprite); // true
trace(mySprite is DisplayObject);// true
trace(mySprite is IEventDispatcher); // true
Is it possible to detect if a variable (extends or) is a certain class or interface with TypeScript?
I couldn't find anything about it in the language specs. It should be there when working with classes/interfaces.
So you could use
Note that this operator is also in ActionScript but it shouldn't be used there anymore:
TypeScript's
instanceof
shares the same problems. As it is a language which is still in its development I recommend you to state a proposal of such facility.See also:
instanceof
Narrowing, which shows howinstanceof
can be used to narrow things