Paul Krill
Editor at Large

TypeScript 5.1 production release arrives

news
Jun 5, 20233 mins

TypeScript upgrade soothes pain points with easier implicit returns for undefined-returning functions and greater type flexibility for getters and setters.

Letterpress, TypeScript
Credit: Jakub Krechowicz/Shutterstock

 TypeScript 5.1, featuring easier implicit returns for undefined-returning functions and allowing unrelated types for getters and setters, is now available as a production release as of June 1.

Version 5.1 features a whole host of coding enhancements for Microsoft’s strongly typed language that builds on JavaScript. With easier implicit returns for undefined-returning functions, TypeScript 5.1 allows undefined-returning functions to have no return statement, fixing a situation in which only functions that could have absolutely no return statements were void-returning and any-returning functions. This meant that even if a developer explicitly indicated that a function returned undefined, at least one return statement was required.

This was a problem if an API expected a function to return undefined, in which case at least one explicit return of undefined or a return statement and an explicit annotation was needed. This behavior was confusing and frustrating, Microsoft said. Also with TypeScript 5.1, if a function has no return expression and is being passed to something that expects a function to return undefined, TypeScript infers undefined for that function’s return type.

TypeScript 5.1 also now allows completely unrelated types for get and set accessor properties, provided they have explicit type annotations. This follows TypeScript 4.3 allowing a get and set accessor pair to specify two different types.

TypeScript 5.1 is available through NuGet or via NPM:

npm install -D typescript

Other new capabilities and improvements in TypeScript 5.1:

  • TypeScript now provides snippet completions when typing out a @param JSDoc tag in both TypeScript and JavaScript files. This can help cut down on typing and jumping around text as developers document code or add JSDoc types in JavaScript.
  • TypeScript 5.1 avoids performing type instantiation within object types known not to contain references to outer type parameters. This could cut down on many unnecessary computations and reduce type-checking time of Material UI’s docs directory by more than 50%.
  • When checking if a source type is part of a union type, TypeScript 5.1 first does a fast lookup using an internal type identifier for that source. If the lookup fails, TypeScript checks for compatibility against every type within the union.
  • TypeScript now only runs on Node.js 14.17 and later.
  • Namespaced attribute names now are supported when using the JSX syntax. Also for JSX, TypeScript 5.1 now looks up a type called JSX.ElementType, which specifies precisely what is valid to use as a tag in a JSX element.
  • Linked editing for JSX tag names allows an editor to edit multiple locations at the same time automatically.
  • When TypeScript’s specified module lookup strategy is unable to resolve a path, it now will resolve packages relative to the specified typeRoots.

The production release follows a May 18, 2023 release candidate and an April 18, 2023 beta. Since the release candidate, builders of TypeScript have iterated slightly on built-in refactorings to move declarations to existing files, but Microsoft believes the implementation still needs improvements. As a result, developers may not be able to access it in most editors at the moment and can only opt in via the nightly version of TypeScript. It is anticipated that TypeScript 5.2 or a future patch release of Version 5.1 will reintroduce this refactoring. Predecessor TypeScript 5.0 was released in March 2023, emphasizing ECMAScript modules.

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