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

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube