This Month in Programming Languages: Proposal for a Typed JavaScript

Microsoft proposal for Javascript to have built-in types

TypeScript has been in recent years a popular option to build javascript applications. According to the Stage of JS survey, TypeScript wins over other tools like Elm or CoffeScript by a huge difference.

TypeScript adds what javascript lacks: support for strong types at compile time; it compiles to javascript and at the end, the types are gone, making it safer for the developer to write correct applications. Some of the drawbacks of TypeScript are the compilation times (depending on the scale of your application) and the configuration setup. Also learning a new language can be something to think about before implementing TypeScript in your project.

Now Microsoft, the sponsor of TS, is presenting a new Stage 0 proposal to add “types” in JavaScript. For those who have used JavaScript for some time, you know that it has JSDoc comments:

 * @param a {number}
 * @param b {number}
function add(a, b) {
    return a + b;

JSDocs are used to add information about types for the IDE or editor, so it could help you with autocompletion. TypeScript can even read these comments by adding a // @ts-check comment at the beginning of the file, but this is still verbose. So why not have both things in one, type checking and a type system that doesn’t add overhead to our developer experience?

This is where this new stage 0 proposal comes in. We could have something similar to TypeScript that tools like the code editor can use to do type checking, but will be completely ignored in runtime.

function add(a: number, b: number) {
    return a + b;

Personally, I believe that this proposal is something to take into consideration for the future of JavaScript. We don’t know if it will be approved by the ECMAScript committee yet, but as time goes by, the development community is getting aware of the power of having a better type system in programming languages.

At Stack Builders, we love strongly typed programming languages like Haskell or TypeScript. This helps us to develop applications that are less prone to error due to type checking. It’s great to see popular languages like JavaScript growing in the same direction and we’re excited about what the future brings for the ecosystem.

Read the complete proposal here

Written by

Sebastian Ávalos