Logo Awesome React

Awesome React

Why static types in Javascript?

  • Details
Many developers have come to love JavaScript for its dynamic typing (the ability of the interpreter to deduce type and type conversions). This feature makes the language incredibly flexible and easy to work with. More importantly, it speeds up development time. However, we’ve recently seen tools in the ecosystem (e.g. Flow.js, TypeScript) that bring the concept of static types to JavaScript. What are static types? Isn’t the point of JavaScript to be dynamically-typed? Why would we use them? When would we not want to use them?

In this talk, we’ll discuss what static types are and look at real-world examples of JavaScript code with static types. As we go through each example, we’ll examine some of the benefits that come with static types, including:

Helping detect errors early
Serving as documentation
Separating data from behavior
Eliminating entire categories of bugs (e.g. Type errors at run time, null exceptions, etc)
Allowing us to refactor with greater confidence
Serving as a domain modeling tool
…as well as some tradeoffs like verbosity, upfront investment to learn, and more.