Paul Krill
Editor at Large

TypeScript 5.8 reaches general availability

news
Mar 3, 20253 mins
JavaScriptTypescriptWeb Development

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.

Letters, type, code
Credit: Daboost/Shutterstock

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 these require() 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 that require() of ECMAScript modules is disallowed under node18 but allowed under nodenext.
  • 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 and dotted.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.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorldโ€™s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorldโ€™s audience of software developers and other information technology professionals. Paul has won a โ€œBest Technology News Coverageโ€ award from IDG.

More from this author