It is proposed to add a syntax with type information to the JavaScript language

Microsoft, Igalia, and Bloomberg have taken the initiative to include a syntax for explicit type definition in the JavaScript specification, similar to the syntax used in the TypeScript language. Currently, the prototype changes proposed for inclusion in the ECMAScript standard have been submitted for preliminary discussions (Stage 0). At the next March meeting of the TC39 committee, it is planned to move to the first stage of consideration of the proposal with the involvement of the expert community from ECMA.

Having explicit type information will avoid many errors in the development process, enable additional optimization techniques, simplify debugging, and make the code more readable and easier for third-party developers to modify and maintain. Type support is proposed to be implemented as an optional feature - JavaScript engines and runtime that do not support type checking will ignore annotations with type information and process code as before, perceiving type data as comments. But type-checking tools will be able, based on the available information, to detect errors related to incorrect use of types.

At the same time, unlike type information specified using JSDoc annotations specified in the form of comments, directly specifying types directly in variable definition constructs will make the code more visual, understandable, and easier to edit. For example, TypeScript-enabled IDEs will be able to immediately highlight errors in typed JavaScript code without additional transformations. In addition, built-in type support will make it possible to run programs written in typed JavaScript dialects such as TypeScript and Flow without transpiling from one language to another.

It is proposed to add a syntax with type information to the JavaScript language

Of the types, it is proposed to add β€œstring”, β€œnumber” and β€œboolean”, which can be used when defining variables, function parameters, object elements, class fields, typed arrays (β€œnumber[]”). It is also proposed to provide support for combined types ("string | number") and generics. let x:string; function add(a: number, b: number) { return a + b; } interface Person { name: string; age:number; } function foo (x: T) { return x; } function foo(x: string | number): string | number { if (typeof x === number) { return x + 1 } else { return x + "!" } }

Source: opennet.ru

Add a comment