4 ms·
Sorry, you're right. I was thinking about "instanceof" which is a native JS feature, and it matches classes nominally.
by slver 6y ago
Sorry, you're right. I was thinking about "instanceof" which is a native JS feature, and it matches classes nominally.
- cnity 6y agoGot you. I was a little disappointed that TS only had structural type checking, but then it's still better than nothing.
- slver 6y agoTo be honest it makes sense for it. It means if something (a library, browser API etc.) has no type, you can write an interface for it and hint for it, without depending on anything else. You can think about the structural type as a hash check on a type. If the hash matches, chances are it's the type you want. Collisions are possible, but highly unlikely, hence why in practice it works great (and we still have instanceof and tagged types).