March 21, 2023
JavaScript could soon have its own type syntax if a proposal submitted by Microsoft and other developers earlier this year becomes a part of the ECMAScript standard. The initiative plans to add “types as comments” support to the JavaScript language, letting developers annotate code with type information that’ll be used by other ecosystem components. The…

JavaScript could soon have its own type syntax if a proposal submitted by Microsoft and other developers earlier this year becomes a part of the ECMAScript standard. The initiative plans to add “types as comments” support to the JavaScript language, letting developers annotate code with type information that’ll be used by other ecosystem components.

The Syntax

The proposed syntax looks like this:

function sayAge(name: string, age: number) { console.log(`${name} is ${age} years old.`); }   sayAge(“JavaScript”, 26);

It’ll be familiar to anyone who’s previously used TypeScript, Microsoft’s typed superset of JavaScript. TypeScript has gained widespread adoption across the industry; this new proposal purports to bring some of its benefits to the wider JavaScript world.

What Isn’t The Proposal?

If it gets approved, this proposal will let you write perfectly valid JavaScript with the type annotations shown above. It’ll be accepted by JavaScript runtimes such as web browsers, Node.js, and Deno that respect the ES standard.

The proposal doesn’t actually extend the JavaScript language though. Your type annotations will be exactly that: inert metadata that have no effect on the JavaScript compiler or your code’s runtime. A…

Read Full Article Source

Leave a Reply

Your email address will not be published. Required fields are marked *