3 ms·
Do you mean instanceof? The javascript operator still works as before? Though typescript is designed around interfaces/ducktyping, which is almost the opposite
by Too 8y ago
Do you mean instanceof? The javascript operator still works as before? Though typescript is designed around interfaces/ducktyping, which is almost the opposite of instanceof; as long as a type satisfies the interface constraints it walks like a duck and should be sufficient.
- mathw 8y agoMaybe they should have had a "quackslike" operator :)
- sime2009 8y agoTypeScript does support writing "quacksLike" functions. The feature is "type guards" and it lets you write a boolean function to test the type of an argument, and TS's flow control code understands it at compile time. const something: Animal = ... if (isDuck(something)) { someThing.quack(); // TS can OK this }