Last JavaScript-based TypeScript arrives in beta

Microsoft has released a beta of TypeScript 6.0, an update to the company’s strongly typed JavaScript variant that promises to be the last release based on the current JavaScript codebase. TypeScript 7.0 will debut a compiler and language service written in Go for better performance and scalability.

The TypeScript 6.0 beta was announced February 11. Developers can access it through npm by running the command npm install -D typescript@beta. A production release of TypeScript 6.0 is planned for March 17. A release candidate for TypeScript 6.0 is due February 24.

Among the key features of TypeScript 6.0 is a new flag, --stableTypeOrdering, to assist with migrations to the planned Go-based TypeScript 7.0. “As announced last year (with recent updates here), we are working on a new codebase for the TypeScript compiler and language service written in Go that takes advantage of the speed of native code and shared-memory multi-threading,” said Microsoft’s Daniel Rosenwasser, principal product manager for TypeScript, in the blog post unveiling the beta. TypeScript 6.0 will in many ways act as a bridge between TypeScript 5.9 and TypeScript 7.0, he said. “As such, most changes in TypeScript 6.0 are meant to help align and prepare for adopting TypeScript 7.0.” But there are some new features and improvements that are not just about alignment.

Also featured in TypeScript 6.0 is support for the es2025 option for both target and lib, less context sensitivity on this-less functions, and new types for Temporal, which provide standard objects and functions for working with dates and times. With the --stableTypeOrdering flag, the type ordering behavior of TypeScript 6.0 matches that of TypeScript 7.0, reducing the number of differences between the two codebases. Microsoft does not necessarily encourage using this flag all the time as it can add a substantial slowdown to type checking (up to 25% depending on the codebase).

With TypeScript 6.0’s es2025, option, the new target adds new types for built-in APIs (e.g. RegExp.escape) and moves a few declarations from esnext into es2025. With this-less functions, if this is never actually used in a function, then it is not considered contextually sensitive. That means these functions will be seen as higher priority when it comes to type inference. For Temporal, the long-awaited ECMAScript Temporal proposal has reached stage 3 and is expected to be added to JavaScript in the near future, Rosenwasser said. TypeScript 6.0 now includes built-in types for the Temporal API, so developers can start using it in TypeScript code via --target esnext or "lib": ["esnext"] or the more granular temporal.esnext.

Other new features and improvements in TypeScript 6.0:

  • New types have been added for “upsert” methods. ECMAScript’s “upsert” proposal, which recently reached stage 4, introduces two new methods on Map and WeakMap. These include getOrInsert or getOrInsertComputed. These methods have been added to the esnext library so they can be used immediately in TypeScript 6.0.
  • RegExp.escape, for escaping regular expression characters such as *, ?, and +, is available in the es2025 library and can be used in TypeScript 6.0 now.
  • The contents of lib.dom.iterable.d.ts and lib.dom.asynciterable.d.ts are fully included in lib.dom.d.ts. TypeScript’s lib option allows developers to specify which global declarations a target runtime has.

Go to Source

Author: