News

What's New in TypeScript 5.2

Microsoft shipped TypeScript 5.2, the latest edition of the popular programming language that adds the optional ability to use type systems when working with JavaScript.

Its host of new features range from better resource management to copying array methods to inline variable refactoring and more.

Microsoft shipped the new version last week after a string of previews, with Daniel Rosenwasser, senior program manager for TypeScript, summarizing the work so far since TypeScript v5.1 shipped in June.

"Since the Beta, we've added a type-checking optimization and made it possible to reference the paths of TypeScript implementation files in type-only imports," he said.

"Since the RC, we've also documented the addition of Copying Array Methods, symbols as WeakMap and WeakSet Keys and Clickable Inlay Parameter Hints. This release also documents a small breaking change around always emitting the namespace keyword in declaration files."

[Click on image for larger view.] Clickable Inlay Parameter Hints (source: Microsoft).

Several of the new features implement functionality introduced in ECMAScript, the standard for JavaScript. One of those is the upcoming Explicit Resource Management feature, described in a GitHub proposal as "a common pattern in software development regarding the lifetime and management of various resources (memory, I/O, etc.). This pattern generally includes the allocation of a resource and the ability to explicitly release critical resources."

Rosenwasser noted that current implementations of the functionality add "noise" to code and could cause other problems. After an exhaustive explanation of the feature, he summarized it this way: "The key idea of the proposal is to support resource disposal -- this clean-up work we're trying to deal with -- as a first class idea in JavaScript."

With the new support enacted by a new built-in symbol called Symbol.dispose, TypeScript will automatically call that disposal method on those resources -- or objects -- when they go out of scope, via using declarations.

Another upcoming ECMAScript feature concerns decorator metadata, which seeks to extend the Decorators proposal (used to extend JavaScript classes) with the added ability for decorators to associate metadata with the value being decorated. "The key idea of this feature is to make it easy for decorators to create and consume metadata on any class they're used on or within," Rosenwasser said.

And yet another ECMAScript feature addressed in TypeScript 5.2 concerns copying array methods, with Rosenwasser explaining that the new version includes definitions for the methods added to ECMAScript in the "Change Array by Copy" proposal. Typically copying arrays requires jumping through some hoops if you want to do so without affecting the original array. That issue is addressed via JavaScript's four new methods to perform various array copying operations without affecting the original data: toSorted, toSpliced, toReversed and with.

Other highlights of the release include:

  • Support for named and anonymous tuple elements
  • Easier method usage for unions of arrays
  • Symbols as WeakMap and WeakSet keys
  • Type-only import paths with TypeScript implementation file extensions
  • Comma completions for object members
  • Inline variable refactoring
  • Optimized checks for ongoing type compatibility
  • Breaking changes and correctness fixes

Going forward, developers can see what's on tap in the TypeScript 5.3 Iteration Plan for the next release, coming Nov 14.

About the Author

David Ramel is an editor and writer at Converge 360.

comments powered by Disqus

Featured

Subscribe on YouTube