Eric Elliott
Aug 8, 2017 · 1 min read

how to create an effective link — that we can rely on

JavaScript does not have static types. What you’re asking for does not exist in the language. Therefore there is no way to do a static type check that you can rely on in JavaScript. That’s why instanceof lies and can be the source of lots of bugs or awkward restrictions. Nominal types (type checking based on the name or identity of a single class/interface) will never work well in JavaScript.

That’s why TypeScript (which adds static annotations and analysis on top of JavaScript) uses structural types, which is basically automated duck typing. You get essentially the same benefits, but without relying on static links.

Essentially, you do feature detection — just ensure the object in question has the properties and methods (the correct shape) required for your function to work.

    Eric Elliott

    Written by

    Make some magic. #JavaScript

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade