News

TypeScript 5.8 Improves Type Checking, Conditional Feature Delayed to 5.9

Microsoft shipped TypeScript 5.8 with improved type checking in some scenarios, but thorny problems caused the dev team to delay related work to the next release.

The plan was for TypeScript 5.8 to include improved conditional return type checking, but due to complexities, those changes were deferred to version 5.9. However, 5.8 does retain a related improvement: more detailed checks within function return expressions, which was not previously announced.

As we reported in our coverage of the beta release, one of the features the team was planning was summarized like this:

Checked Returns for Conditional and Indexed Access Types: TypeScript 5.8 enhances type inference by allowing functions to have return types that depend on their parameters. This means that the return type can be more precisely determined based on the input, reducing type errors and improving code clarity.

However, Daniel Rosenwasser, principal product manager, explained why that was dropped in a Feb. 28 announcement. "Based on some of the limitations and changes we wanted to make, we decided to iterate on the feature with the goal of shipping it in TypeScript 5.9," he said. "However, as part of this work, we added more granular checks for branches within return expressions. This enhancement was not documented in the beta post, but will remain in TypeScript 5.8."

That enhancement allows TypeScript to more accurately catch bugs in conditional expressions within return statements, leading to more robust code. Specifically, each branch of the conditional is now checked against the function's declared return type, which can help catch subtle bugs where the wrong type might be returned in one of the branches, preventing the any type from masking the issue.

Other highlights of TypeScript 5.8, which saw no major changes made since the release candidate, include:

  • Improved ECMAScript Module Support: Developers can now use require() to import ECMAScript modules when using the --module nodenext flag. This makes it easier to work with both CommonJS and ESM in Node.js projects, improving interoperability between module systems.
  • New --erasableSyntaxOnly Compiler Option: This new flag ensures that TypeScript-specific syntax without runtime effects can be removed safely. It aligns with Node.js's experimental support for running TypeScript files directly, making it easier to transition from TypeScript to JavaScript execution.
  • Performance Improvements: TypeScript 5.8 includes optimizations that speed up type checking and compilation times, resulting in a smoother development experience, especially for large codebases.
  • Better Inference for Generics: The TypeScript compiler now makes smarter guesses about generic types, reducing the need for explicit type annotations and making code more concise while maintaining strong type safety.

The dev team is now working on TypeScript 5.9, with no specific features mentioned for that release. Early versions of that release can be tried out in nightly builds that can be installed via npm or the VS Code TypeScript Nightly extension, which is nearing 5 million installs.

About the Author

David Ramel is an editor and writer at Converge 360.

comments powered by Disqus

Featured

  • Mastering AI Development and Building AI Apps with GitHub Copilot

    Two Microsoft experts explain how GitHub Copilot is evolving from a coding assistant into a broader platform for building, customizing and testing AI-powered developer workflows.

  • VS Code 1.123 Adds Agent Session Sync, 1M Context Windows

    Microsoft released Visual Studio Code 1.123 on June 3, adding agent-focused features, larger model context support, integrated browser updates and a new delay for some automatic extension updates.

  • Copilot Billing Shock Hits Developers

    Developer complaints about GitHub Copilot's new usage-based billing model have centered on unexpectedly rapid AI credit consumption, and neither GitHub nor Microsoft has responded directly to the backlash, though they have previously published guidance to lessen model usage costs.

  • Hands On with GitHub Copilot App Technical Preview: Turning a Blazor Issue into a PR

    GitHub's brand-new Copilot desktop app, in technical preview, handled a small Blazor issue from planning through pull request creation, but the hands-on test also showed why developers still need to verify agent work in the running app before merging.

Subscribe on YouTube