Microsoft 11796 Published by

Daniel Rosenwasser has announced TypeScript 5.7 Beta, which introduces several new features. These include checks for never-initialized variables, path rewriting for relative paths, ECMAScript 2024 runtime support, and project ownership search in ancestor configuration files.

TypeScript now enforces rules to prevent runtime problems when importing from a.json file via the "nodenext" module. It also supports V8 compile caching in Node.js via the new API module.enableCompileCache(). Notable behavioral changes include more implicit errors on functions that return null or undefined, as well as support for V8 compile caching in Node.js. These modifications are intended to improve the user experience and eliminate the need to re-run build tasks.





TypeScript 5.7 Beta

Today we are announcing the availability of TypeScript 5.7 Beta.

To get started using the beta, you can get it through npm with the following command:

npm install -D typescript@beta

Let’s take a look at what’s new in TypeScript 5.7!

Checks for Never-Initialized Variables

For a long time, TypeScript has been able to catch issues when a variable has not yet been initialized in all prior branches.

Path Rewriting for Relative Paths

There are several tools and runtimes that allow you to run TypeScript code "in-place", meaning they do not require a build step which generates output JavaScript files. For example, ts-node, tsx, Deno, and Bun all support running .ts files directly. More recently, Node.js has been investigating such support with --experimental-transform-types and --experimental-strip-types. This is extremely convenient because it allows us to iterate faster without worrying about re-running a build task.

Support for --target es2024 and --lib es2024

TypeScript 5.7 now supports --target es2024, which allows users to target ECMAScript 2024 runtimes. This target primarily enables specifying the new --lib es2024 which contains many features for SharedArrayBuffer and ArrayBufferObject.groupByMap.groupByPromise.withResolvers, and more. It also moves Atomics.waitAsync from --lib es2022 to --lib es2024.

Searching Ancestor Configuration Files for Project Ownership

When a TypeScript file is loaded in an editor using TSServer (like Visual Studio or VS Code), the editor will try to find the relevant tsconfig.json file that "owns" the file. To do this, it walks up the directory tree from the file being edited, looking for any file named tsconfig.json.

Validated JSON Imports in --module nodenext

When importing from a .json file under --module nodenext, TypeScript will now enforce certain rules to prevent runtime errors.

For one, an import attribute containing type: "json" needs to be present for any JSON file import.

Support for V8 Compile Caching in Node.js

Node.js 22 supports  a new API called module.enableCompileCache(). This API allows the runtime to reuse some of the parsing and compilation work done after the first run of a tool.

TypeScript 5.7 now leverages the API so that it can start doing useful work sooner. In some of our own testing, we’ve witnessed about a 2.5x speed-up in running tsc --version.

Notable Behavioral Changes

This section highlights a set of noteworthy changes that should be acknowledged and understood as part of any upgrade. Sometimes it will highlight deprecations, removals, and new restrictions. It can also contain bug fixes that are functionally improvements, but which can also affect an existing build by introducing new errors.

More Implicit any Errors on Functions Returning null and undefined

When a function expression is contextually typed by a signature returning a generic type, TypeScript now appropriately provides an implicit any error under noImplicitAny, but outside of strictNullChecks.

Announcing TypeScript 5.7 Beta - TypeScript