Recently, Microsoft announced an ambitious project -- it is supporting and collaborating on an initial "phase 0" proposal: adding optional Type Annotations to ECMAScript, the official JavaScript standard.
According to Microsoft's official information: "This proposal aims to enable developers to add type annotations to JavaScript code, allowing type checkers outside of JavaScript to check these annotations, and at runtime, the JavaScript engine ignores them and treats types as annotations. ."
The purpose of the above proposal is to allow developers to run programs written in TypeScript, Flow, and other statically typed "supersets" of JavaScript without any compilation (if they stay in some sizable subset of the language). within the set).
The above proposal is fully explained in a March 9 blog post by Daniel Rosenwasser, Senior Program Manager at TypeScript, Microsoft. If the proposal moves forward, it could take years.
The blog post explains that the proposal is related to recent trends of faster JavaScript iterations and fewer build steps that are making JavaScript coding faster and easier. At the same time, this trend has also been fueled by modern evergreen browsers, which typically no longer require developers to compile new versions of JavaScript to run on older runtimes.
As pointed out in the previous proposal, the syntax in this proposal acts like a comment, so it doesn't affect how the surrounding code operates. This is also explained in Daniel Rosenwasser's blog post above:
"The idea of this proposal is that JavaScript can create a set of syntaxes for types that are completely ignored by the engine, but can be used by tools like TypeScript, Flow, etc." "This allows us to keep what developers love about TypeScript - its types Inspect and edit the experience while eliminating the need for a build step in development."
In this new scenario, when it comes to writing and running code, the developer's inner loop looks like this:
Since JavaScript's type syntax has been around before, and developers have many different views on how any such feature works, many details haven't been specified.
To this, Daniel Rosenwasser added that at least syntax needs to be added for the following:
- Type annotations for variables and functions
- (optional) modifiers(?) parameters and class members
- Type declarations (interfaces and type aliases)
- Type assertion operators (as and !)
While other constructs such as visibility modifiers (such as public, private, and protected) may also be in scope, other constructs such as enums, namespaces, and parameter properties are not because they have observable runtime behavior.
According to Daniel Rosenwasser, "These features could be proposed as separate ECMAScript features based on feedback, but our current goal is to support some large subset of TypeScript that we think could be a valuable addition to JavaScript."
It is reported that the proposal will be presented at the upcoming TC39 ("Designated JavaScript") plenary meeting in March 2022.
TC39 is a committee of JavaScript developers, implementers, academics, and stakeholders who work with the community to maintain and develop the definition of JavaScript, hoping to jump from "Phase 0" to "Phase 1."
Rosenwasser emphasized: "Achieving Stage 1 means that the standards committee believes that support for type syntax is worth considering for ECMAScript". "It's not something that's sure to be a buzz, there's a lot of valuable perspective within the committee, and we do hope there will be some skepticism. A proposal like this gets a lot of feedback and proper scrutiny, so it could involve a lot of design changes. , it may take years to produce results.”
"But if we do this, we have a chance to make one of the most impactful improvements to the JavaScript world. We're excited about it, and hope you are too."
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。