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

  • Hands On: New VS Code Insiders Build Creates Web Page from Image in Seconds

    New Vision support with GitHub Copilot in the latest Visual Studio Code Insiders build takes a user-supplied mockup image and creates a web page from it in seconds, handling all the HTML and CSS.

  • Naive Bayes Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the naive Bayes regression technique, where the goal is to predict a single numeric value. Compared to other machine learning regression techniques, naive Bayes regression is usually less accurate, but is simple, easy to implement and customize, works on both large and small datasets, is highly interpretable, and doesn't require tuning any hyperparameters.

  • VS Code Copilot Previews New GPT-4o AI Code Completion Model

    The 4o upgrade includes additional training on more than 275,000 high-quality public repositories in over 30 popular programming languages, said Microsoft-owned GitHub, which created the original "AI pair programmer" years ago.

  • Microsoft's Rust Embrace Continues with Azure SDK Beta

    "Rust's strong type system and ownership model help prevent common programming errors such as null pointer dereferencing and buffer overflows, leading to more secure and stable code."

  • Xcode IDE from Microsoft Archrival Apple Gets Copilot AI

    Just after expanding the reach of its Copilot AI coding assistant to the open-source Eclipse IDE, Microsoft showcased how it's going even further, providing details about a preview version for the Xcode IDE from archrival Apple.

Subscribe on YouTube

Upcoming Training Events