News

New Features in Generally Available TypeScript 5.1

Microsoft released TypeScript 5.1, introducing several new features and performance improvements that aim to enhance the developer experience and productivity of the programming language that adds types to JavaScript.

One of the new features is allowing undefined-returning functions to have no return statement and inferring undefined for their return type in certain circumstances. This simplifies the code and avoids unnecessary errors when writing functions that return undefined explicitly or implicitly.

Another new feature is allowing completely unrelated types for get and set accessor properties that have explicit type annotations. This enables developers to model APIs that have different types between their getters and setters, such as the style property in the DOM and CSSStyleRule API.

TypeScript 5.1 also supports namespaced attribute names in JSX, a JavaScript extension syntax that allows devs to write HTML and JavaScript together. Updates allow developers to use custom attributes with namespaces in their JSX elements, which can be useful for integrating with third-party libraries that use namespaced attributes.

There is also support for linked editing for JSX tag names, which lets developers edit multiple locations at the same time automatically. This feature can help developers rename JSX elements more easily and consistently.

Furthermore, TypeScript 5.1 provides snippet completions for @param tags in JSDoc comments, which can help developers document their code or add JSDoc types in JavaScript files. That can reduce some typing and jumping around text as developers add or edit their JSDoc comments.

Language/Compiler Performance Boosts
In addition to the new features above, TypeScript 5.1 also improves the performance of various aspects of the language and compiler. For example, it optimizes type instantiation within object types that don't contain references to outer type parameters, which can potentially cut down on many unnecessary computations. The update also optimizes union type checking by avoiding a full walk against every other type in the union when relating a literal type to a union of purely literal types. Also, the release improves JSDoc parsing by moving more logic for breaking down JSDoc comments into the scanner/tokenizer, causing the scanner to to return larger chunks of content directly to the parser for further work.

Breaking Changes
TypeScript 5.1 also introduces some breaking changes that affect the runtime and configuration requirements of the language. For instance, TypeScript 5.1 requires Node.js 14.17 and later as the minimum runtime, as it ships JavaScript functionality that was introduced in ECMAScript 2020. Also, the new update disables parent directory look-ups for typeRoots when the typeRoots option is specified in a tsconfig.json but resolution to any typeRoots directories has failed.

What's Next
"Our team is already hard at work on TypeScript 5.2, and you can read the specifics on the TypeScript 5.2 Iteration Plan," said Daniel Rosenwasser, senior program manager for the language, in the June 1 announcement of v5.1.

[Click on image for larger view.] TypeScript 5.2 Iteration Plan (source: Microsoft).

"In addition to planned work items, this iteration plan describes target release dates which you can use to for your own plans. The best way to play with what's next is to try a nightly build of TypeScript, and use the nightly editing experience too."

The v5.2 iteration plan includes links to get more information on planned work regarding: compiler/lanuage; editor/language service; performance; website/docs; and infrastructure.

About the Author

David Ramel is an editor and writer at Converge 360.

comments powered by Disqus

Featured

  • The AI-Powered Software Development Lifecycle

    René van Osnabrugge makes the case that AI's biggest opportunity in software development is not faster coding -- it's reducing the friction everywhere else in the SDLC.

  • Copilot Usage-Based Billing Gets a Token Dashboard

    Microsoft is keeping Visual Studio's new built-in Agent Skills switched off by default while a public dashboard measures whether their performance gains justify the additional tokens they may consume.

  • VS Code 1.129 Introduces Agent Host and Experimental Agents Window Editor

    Visual Studio Code 1.129 adds a dedicated process for running AI agent sessions and an experimental docked editor for reviewing agent-generated changes.

  • .NET 11 Preview 6 Roundup: ASP.NET Core, MAUI, C#, EF Core and SDK Updates

    Microsoft's sixth .NET 11 preview advances async validation, C# unions, cross-platform UI controls, database queries, testing tools, Native AOT and container images.

Subscribe on YouTube