Microsoft Releases TypeScript 5.8 with Granular Checks for Branches in Return Expressions

Max Carter

Max Carter

March 04, 2025 · 3 min read
Microsoft Releases TypeScript 5.8 with Granular Checks for Branches in Return Expressions

Microsoft has announced the general availability of TypeScript 5.8, the latest version of its strongly typed superset of JavaScript. While the release brings several new features and improvements, one notable addition is more granular checks for branches within return expressions.

However, a limited form of checking against conditional types in return statements, introduced during the beta stage, has been dropped from the general availability release. Microsoft plans to iterate on the feature and release it in TypeScript 5.9.

TypeScript 5.8 adds more granular checks for branches within return expressions by special-casing conditional expressions directly inside return statements. Each branch of the conditional is checked against the declared return type of the containing function, if one exists.

In addition to the new checks, TypeScript 5.8 introduces several other features and improvements. These include optimizations to improve the time to build a program and update a program based on a file change in either --watch mode or editor scenarios. TypeScript now avoids any array allocations involved while normalizing paths, and when edits are made that do not fundamentally change the fundamental structure of a project, TypeScript avoids re-validating options provided to it.

Other notable features in TypeScript 5.8 include support for require() of ECMAScript modules in --module nodenext, a stable –-module node18 flag for users of Node.js 18, and an –-erasableSyntaxOnly flag to error on most TypeScript-specific constructs that have runtime behavior.

TypeScript 5.8 also addresses issues raised by Node.js recently unflagging a mode called --experimental-strip-types, which requires that any TypeScript-specific syntax cannot have runtime semantics. This is achieved by combining the --erasableSyntaxOnly flag with the --verbatimModuleSyntax flag, ensuring that a module contains appropriate import syntax and that import elision does not take place.

Furthermore, TypeScript 5.8 consistently preserves entity names in computed property names in classes, making computed properties have more predictable emit in declaration files.

Developers interested in trying out early versions of TypeScript 5.9 can do so through nightly builds from NPM (run npm install typescript@next) or through the Visual Studio Code TypeScript Nightly extension.

The release of TypeScript 5.8 follows the release of TypeScript 5.7 in November, which featured improved error reporting. A release candidate of TypeScript 5.8 was issued on February 13, with general availability announced on February 28.

As the TypeScript ecosystem continues to evolve, the latest release demonstrates Microsoft's ongoing commitment to improving the development experience for developers working with JavaScript and TypeScript.

Similiar Posts

Copyright © 2024 Starfolk. All rights reserved.