Microsoft introduces more granular checks for branches within return expressions in TypeScript 5.8, punts checking against conditional types in returns to TypeScript 5.9.

Microsoft’s TypeScript 5.8, the latest version of the company’s strongly typed superset of JavaScript, has reached general availability (GA). However, one new feature introduced at the beta stage, a limited form of checking against conditional types in return statements, was dropped from the GA release.
General availability was announced February 28. Since the beta release, which arrived January 29, TypeScript’s builders pulled back some work on how functions with conditional return types are checked. The plan now is to iterate on the feature and release it in TypeScript 5.9.
TypeScript 5.8 does add more granular checks for branches within return expressions. With these granular checks, the type system special-cases conditional expressions directly inside return
statements. Each branch of the conditional is checked against the declared return type of the containing function, if one happens to exist.
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 February 13.
Other new and improved features in TypeScript 5.8:
- Optimizations have been introduced to improve the time to build a program as well as update a program based on a file change in either
--watch
mode or editor scenarios. TypeScript now avoids any array allocations that would be involved while normalizing paths. Also, when edits are made that do not fundamentally change the fundamental structure of a project, TypeScript now avoids re-validating options provided to it. - TypeScript 5.8 adds support for
require()
of ECMAScript modules in--module nodenext
. When--module nodenext
is enabled, TypeScript will avoid issuing errors on theserequire()
calls to ESM files. - TypeScript introduces a stable
–-module node18
flag. Users of Node.js 18 are thus provided with a flag offering a stable point of reference that does not incorporate certain behaviors that are in–-module next
. Among these behaviors is thatrequire()
of ECMAScript modules is disallowed undernode18
but allowed undernodenext
. - TypeScript 5.8 introduces an
–-erasableSyntaxOnly
flag. When enabled, TypeScript will error on most TypeScript-specific constructs that have runtime behavior. Typically, developers will want to combine this flag with the--verbatimModuleSyntax
, which ensures that a module contains appropriate import syntax, and that import elision does not take place. This 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. Thus it must be possible to easily erase or “strip out” any TypeScript-specific syntax from a file, leaving behind a valid JavaScript file. - To make computed properties have more predictable emit in declaration files, TypeScript 5.8 consistently preserves entity names (
bareVariables
anddotted.names.that.look.like.this
) in computed property names in classes.
Developers can try out early versions of TypeScript 5.9 from nightly builds from NPM (run npm install typescript@next
) or through the Visual Studio Code TypeScript Nightly extension.