Microsoft has put forward a new proposal to bring an optional type syntax to JavaScript, which could make JavaScript natively come with some of the features of TypeScript, making the TypeScript language faster and easier to use.

optional type syntax to JavaScript

Specifically, the proposal calls for Type Annotations to be added to JavaScript code, allowing type annotations to be checked by external type checkers. At runtime, the JavaScript engine would ignore these annotations and treat these types as annotations. The proposal would require JavaScript to delineate a syntax for types that the JavaScript engine would ignore, but tools such as TypeScript, Flow, etc. could use. This proposal would add an optional type syntax to ECMAScript.

The proposal is intended to allow developers to run programs written in TypeScript, Flow or other statically typed JavaScript supersets without the need for transcripts. Microsoft said in the announcement that the new syntax will effectively serve as a comment without changing the way the code runs.

In its proposal, Microsoft also said that the case for static type checking has proven quite successful over the past decade. Significant investments in JavaScript (such as Microsoft TypeScript, Google Closure Compiler, and Facebook Flow) have provided convenient syntax for declaring and using types in JavaScript, and have yielded the productivity gains seen in other statically typed languages. Most of their syntax does not affect runtime semantics, and in fact most of the work to convert these variants to plain JavaScript is in removing types.


In addition, static typing has been a strongly requested feature by JavaScript developers in the 2020 and 2021 JS surveys.

The rise of type syntax in JavaScript has coincided with the rise of lower-level compilation (or transcoding). Because type syntax is not natively supported in JavaScript, there must be a tool that can remove these types before running the code. For type systems like TypeScript and Flow, it makes sense to combine a type-removal step with syntax degradation so that users do not need to run a separate tool.

This proposal would reduce the need for build steps, make some development setups easier, and users would be able to run the code they write more simply.

Microsoft’s proposal does not require TypeScript type checking to be placed in every browser and JavaScript runtime, nor does it require a new type checker to be placed in the browser. Microsoft believes this would create runtime performance and compatibility issues for JavaScript and TypeScript users, and potentially prevent innovation. The proposal is currently in Stage 0, and more information about the proposal can be found on Microsoft’s official page.