4 ms·
Maybe they should have had a "quackslike" operator :)
by mathw 8y ago
Maybe 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 }