Microsoft TypeScript 5.0 is nearly done, complete with ECMAScript Decorators

Microsoft TypeScript 5.0 is nearly done, complete with ECMAScript Decorators

The TypeScript team has rolled out TypeScript 5.0 RC, with Microsoft senior program manager Daniel Rosenwasser saying that “we expect no further changes apart from critical bug fixes.” The full release is planned for March 14th. The big new feature is ECMAScript Decorators, a feature which extends classes via annotations called Decorator expressions.

Decorators are also a forthcoming ECMAScript feature in Stage 3, which means it is close to completion. ECMAScript, the formal standard for JavaScript, has an annual release cycle for updates to the standard, generally in June, but Decorators are not currently part of the 2023 draft. Note though that Rosenwasser is listed as a co-author and champion of the ECMAScript proposal, which is a clue that the TypeScript and ECMAScript teams have a collaborative approach. TypeScript developers will get this feature ahead of the ECMAScript specification, but the two languages are not in competition. In the meantime, the TypeScript compiler will output compatible JavaScript that runs correctly in today’s browsers.

Decorator expressions are a huge feature and have been work in progress for a long time. Rosenwasser describes it as a “feature that allows us to customize classes and their members in a reusable way.” When a decorator is added to a class method, class field or the class itself, a related decorator function wraps the original with its own additional code. Rosenwasser gives an example that adds logging to every method to which it is applied.

Other features in TypeScript 5.0 include const modifiers for type parameters and enhanced enums. The satisfies operator was introduced in 4.9 as we discussed here, but now in version 5.0 has a related tag that works for the document generator JSDoc. Similarly @overload is now a supported JSDoc tag.

Regarding performance, the TypeScript 5.0 compiler is just over 10 percent faster than before, according to tests.

As the ECMAScript specification gets richer, will TypeScript still be needed? Probably it will, since the relationship is a healthy one, with TypeScript meeting the need for type-checked code while JavaScript remains as a kind of universal runtime in browsers. There is debate though, particularly since another ECMAScript proposal called Type Annotations brings a core benefit of TypeScript to JavaScript itself, however, these annotations will not be enforced at runtime. The comments to a post last year by Rosenwasser, on the subject of type syntax in JavaScript itself, show both sides of the debate, with some arguing that JavaScript badly needs this feature, and others stating that JavaScript should be kept clean and simple rather than becoming a kind of TypeScript-lite.