Bbabo NET

Science & Technology News

Microsoft Supports Adding Optional and Erasable Type Syntax to JavaScript

Microsoft has backed a proposal to add an optional and erasable type syntax to JavaScript to make the TypeScript language faster and easier to use.

In a new blog post, the software giant provided more information about the proposal and what its goals are. Essentially, the proposal requires the addition of type annotations to JavaScript code that can be checked by external type checkers and treated as comments by the JavaScript engine at runtime.

As part of the proposal, it is also necessary to create a set of syntax for types that engines will ignore, but will be able to use TypeScript, Flow, and other tools. If the proposal is approved, developers will be able to run programs in TypeScript, Flow, and other languages.

The new proposal came from Gil Tayar, Microsoft's Daniel Rosenwasser, Igalia's Romulo Sintra, and Bloomberg's Rob Palmer. It was published on GitHub. This month the team will present their proposal to the ECMAScript Standards Committee.

The authors of the idea said that over the past decade, static type checking has been quite successful. In addition to Microsoft's TypeScript, Google has created its Closure Compiler and Facebook has introduced Flow. Static typing has been recognized as the number one feature missing from a programming language. 69% of respondents in the 2021 State of JavaScript survey said they use TypeScript to compile JavaScript.

It's worth noting that Microsoft doesn't advocate adding TypeScript type checking to every browser and JavaScript runtime. Instead, the company offered a TypeScript-compliant JavaScript syntax that can be used by any type checker but ignored by JavaScript engines. For this to happen, JavaScript would minimally need to add syntax for things like type annotations on variables and functions, optionality modifiers on class parameters and members, type declarations (interfaces and type aliases), and type assertion statements, all without affecting code execution. Functions such as visibility modifiers (such as public, private, and protected) can be offered as separate ECMAScript functions.

Microsoft Supports Adding Optional and Erasable Type Syntax to JavaScript