Microsoft has backed a proposal to bring optional and erasable type syntax to JavaScript (opens in new tab) in an effort to make its TypeScript (opens in new tab) language both faster and easier to use.
In a new blog post (opens in new tab), the software giant provided further insight on the proposal and what it aims to do. Essentially, the proposal is calling for type annotations to be added to JavaScript code that can be checked by external type checkers and treated as comments by a JavaScript engine at runtime.
A set of syntax for types that engines would ignore but TypeScript, Flow and other tools could use would also need to be created as part of the proposal.
If the proposal is approved, developers would be able to run programs in TypeScript, Flow and other static typing supersets of JavaScript without the need for transpilation according to InfoWorld (opens in new tab).
Type syntax in JavaScript
The new Stage 0 proposal (opens in new tab) was written and put forth by Gil Tayar, Microsoft's Daniel Rosenwasser, Igalia's Romulo Cintra and Bloomberg's Rob Palmer and is available to read in its entirety on GitHub (opens in new tab).
The reason behind the proposal is that over the past decade, static type checking has proven to be fairly successful. In addition to Microsoft's TypeScript, Google created its Closure Compiler (opens in new tab) while Facebook built Flow to provide syntax for declaring and using types in JavaScript.
> Python could soon rival JavaScript for web applications (opens in new tab)
> This ancient programming language is way more common than we all thought (opens in new tab)
> It's official, these are the most hated programming languages around (opens in new tab)
At the same time, 69 percent of respondents in the 2021 State of JavaScript (opens in new tab) survey said that they use TypeScript to compile JavaScript and static typing was voted as the number one feature missing from the programming language (opens in new tab).
It's worth noting that Microsoft isn't calling for TypeScript's type checking to be added to every browser (opens in new tab) and JavaScript runtime. Instead, the company has proposed a JavaScript syntax compatible with TypeScript that could be used by any type checker while being ignored by JavaScript engines.
- We've also rounded up the best laptops for programming (opens in new tab) and the best JavaScript online courses (opens in new tab)
Via InfoWorld (opens in new tab)