New TypeScript operator finds coding mistakes

Upgrading to Microsoft’s TypeScript 4.9 A popular, strongly-typed language built on JavaScriptis now available as a production release. This update includes satisfies An operator that can catch errors.

When satisfies, developers can validate that the type of an expression matches some type without changing the type of the result of the expression. This operator can be used to catch possible errors, such as checking that an object has all keys of a certain type, but nothing more.

Also, in TypeScript 4.9, in Operators are now more powerful at filtering types that don’t list properties.Instead of leaving them alone, the language intersects those types Record<”property-key-being-checked”, unknown>.

TypeScript 4.9 also has better checks on methods. in Used to ensure that a valid property key is used.

Introduced on November 15thfollowing the Beta and Release Candidate stages, TypeScript 4.9 is available for download Via NuGet Or via NPM using the following command:

npm install -D typescript

Other new features and improvements in TypeScript 4.9:

  • File watching is powered by file system events by default. It only reverts to polling if the developer fails to set up an event-based watcher.This should provide a less resource intensive experience at runtime –-watch mode, or in a TypeScript-powered editor such as Visual Studio Code or Visual Studio.
  • Promise.resolve now Awaited A type that unwraps the passed Promise-like type.This means it will return the right more often Promise type, but that improved type might break existing code if you were expecting any Also unknown Instead of Promise.
  • TypeScript errors out on direct comparisons with NaN values ​​and suggests some variations Number.isNAN instead.
  • TypeScript now supports an upcoming feature in ECMAScript called auto-accessors. It is declared like a class property, except that accessor keyword.
  • To improve performance, forEachChild function has been rewritten to use function table lookups instead of switch statements across syntax nodes. We’ve also optimized the way TypeScript retains information about types in true branches of conditional types.
  • To optimize the replacement type, SubstitutionType The object no longer contains substitute properties that represent valid alternatives.Instead, they have constraint property.

typescript 5.0 is scheduled for a beta release on January 24, 2023, with a release candidate set for February 28th and a production release expected to arrive on March 14th. TypeScript 4.8 shipped on August 25thbrings accuracy and consistency improvements, and file watcher fixes.

TypeScript is on the rise. Circle CI’s State of software delivery in 2022 TypeScript has reportedly surpassed JavaScript as the most popular DevOps language. CircleCI cites developer ease of use as the reason for the surge.

Predecessor TypeScript 4.8 shipped on August 25thbrings accuracy and consistency improvements, and file watcher fixes.

Copyright © 2022 IDG Communications, Inc.

https://www.infoworld.com/article/3674814/new-typescript-operator-finds-coding-mistakes.html#tk.rss_all New TypeScript operator finds coding mistakes

Show More
Back to top button