A very interesting Stage-0 proposal is to bring optional and erasable type syntax to JavaScript.
💁♂️ Stage-0?
The Technical Committee which is concerned with the standardization of ECMAScript (i.e. TC39) has a 5 stage process in place, ranging from stage-0 to stage-4, by which it develops a new language feature.
Stage-0 is the Strawperson stage which collects all proposals without any acceptance criteria. It's intended to spark the discussion. It is only when a proposal reaches Stage 4 that it is ready to become part of the ECMAScript Specification.
The proposed syntax looks like this:
function add(a: number, b: number) {
return a + b;
}
The type hints wouldn’t be used by JS itself though — so you won’t get a runtime error if you pass something other than a number into that function — but, instead, they’re meant for your IDE (or a tool) to read so that your IDE can give you hints about the argument types while you’re crafting your code.
The idea of this proposal is that JavaScript could carve out a set of syntax for types that engines would entirely ignore, but which tools like TypeScript, Flow, and others could use. This allows us to keep the things you love about TypeScript – its type-checking and editing experience – while removing the need for a build step in development.
You can compare it to typing some JSDoc above a function: they’re only useful for the IDE, not the JS runtime, and can keep you from writing bad code.
A Proposal For Type Syntax in JavaScript →
ECMAScript proposal: Types as Comments →