if (my_var instance_of MyCustomType)
in TS, but you could in normal statically typed languages, correct?
if (my_var instance_of MyCustomType)
in TS, but you could in normal statically typed languages, correct?
The issues tend to start cropping up as you get further into TS-specific types like generic types. In a statically typed language you can inquire about the specifics of an implementation of a generic directly, and often even dispatch directly on that type. JS has no concept of your generic wrapper type and you need some other flag or logic to determine the runtime type of your generic code.
But in TS itself structural typing is used everywhere for actual type checking (except for classes with private members), and from my understanding there's no way to have TS help you check at runtime whether a type is structurally compatible with a value.
I wrote a library [1] that does this in a readable pattern-matching way, hope you find it useful!