My favorite type of programming
Is TypeScript the future of JavaScript? Are types ever going to be incorporated in ECMAScript?

There are a few things I remember from SpringTree’s visit to JSConf Berlin back in June 2018. It was very hot, we saw some great speakers, like Ryan Dahl, Remy Sharp etc. Interesting food choices during the lunch breaks, and I got a chance to ask a question to the members of the TC39 committee!
We couldn’t ask questions directly to the committee, we had to submit questions via Twitter. The preferred way of communicating with the audience during that conference. This was my question / tweet:
ECMA International’s TC39 is a group of JavaScript developers, implementers, academics, and more, collaborating with the community to maintain and evolve the definition of JavaScript
My question was picked up by the panel. They answered that, basically, nobody has come up with a design that works well enough for JavaScript, and works universally enough for them to feel comfortable adding types to the language. And besides, other projects like TypeScript, Babel and Flow were doing a good job so far, there really wasn’t any need for it.
Well that was 2018. Now it’s March 2022, and apparently someone found a design that works! It’s still very early days, what we call “stage 0” of a TC39 proposal. What translates to:
“Planned to be presented to the committee by a TC39 champion”.
In this case champions (plural). These are; Rob Palmer (TC39 member), Daniel Rosenwasser (author at TypeScript), Romulo Cintra (TC39 member), Gil Tayar (Roundforest), and others.
Ok, so how does it work? Here’s an example of the proposed syntax:
function add(a: number, b: number) {
return a + b;
}
In this example the arguments x and y have type annotations: The type number, separated by a colon.
At runtime, the JavaScript engine will completely ignore these types, as if they were comments. Fun fact; code comments tend to be ignored by developers anyway, but we’re getting off-topic. During development, type checkers can statically analyze the annotations and provide developers feedback about potential issues with their code.
It doesn’t stop with simple type annotations like the example above. More complicated annotations are also proposed like: Interfaces (interface), type aliases (type), type assertions (as), generics (fetchMovies<MovieEntry[]>(...)), and more.
Personally, I’m excited about this proposal. We’ve been using TypeScript religiously at SpringTree for the last 8 years, and we wouldn’t want to go back. But it always adds a layer of complexity on top of your project. If it’s added to JavaScript directly, that means that type notations will be standardized. Which means better development tooling support. Compiling won’t be necessary anymore. No intermediate files would be needed for code execution, like source maps, type definition files (*.d.ts), type configuration files (tsconfig.json), etc.
This is all optional. If you don’t like TypeScript, or type annotations in general, you can just not use it. One point of criticism I read online about this proposal is how this will make your source bundles unnecessarily bloated. This argument doesn’t make any sense to me. If you don’t minify your source code in production applications, then you’re doing something wrong! Remember, these types are essentially treated as code comments. Or you’re the type of developer that doesn’t believe in code comments in the first place. In that case, I would like to reiterate my previous statement: you’re doing something wrong.
We at SpringTree will monitor the progress of this proposal closely. But these things take time, so we won’t be saying goodbye to TypeScript any time soon. It still remains our favorite type of programming language, pun intended.
Are you interested in learning more about SpringTree? click here.
Sources:
Types as comments proposal: Proposal
What is TC39: Link
My original tweet: Tweet
Conference video: Video
The accompanying blog post: Blog Post