TypeScript spots type problems before they turn into runtime errors and is as such of a huge help to developers. But at the end of the day JavaScript will run on the machine. That makes type-based decisions harder in TypeScript than in other typed languages, as types are unavailable at runtime. This is something you have to keep in mind when writing your code, as classic type introspection techniques won’t help you here. For example, JavaScript’s instanceof will work with JavaScript primitive types or classes, but not with TypeScript interfaces.

#typescript #javascrip

Tagged Unions and User-Defined Type Guards in TypeScript
1.10 GEEK