satisfies operator that can catch errors.
satisfies, developers can validate that the type of an expression matches some type, without changing the resulting type of the expression. This operator can be used to catch possible errors, such as ensuring that an object has all the keys of some type, but no more than that.
Also in TypeScript 4.9, the
in operator has been made more powerful when narrowing types that do not list the property. Instead of leaving them as is, the language will intersect their types with
TypeScript 4.9 also tightens up checks around how
in is used, to ensure that valid property keys are being used.
npm install -D typescript
Other new capabilities and improvements in TypeScript 4.9:
- File watching is powered by file system events by default, only falling back to polling if developers fail to set up event-based watchers. This should provide a less resource-intensive experience when running
–-watchmode or running with a TypeScript-powered editor like Visual Studio Code or Visual Studio.
Promise.resolvenow uses the
Awaitedtype to unwrap Promise-like types passed to it. This means that it more often returns the right
Promisetype, but that improved type can break existing code if it was expecting
unknowninstead of a
- TypeScript now errors on direct comparisons against the NaN value and will suggest some variation of
- TypeScript now supports an upcoming feature in ECMAScript, called auto-accessors, which are declared just like properties in classes, except that they are declared with the
- To improve performance, the
forEachChildfunction has been rewritten to use a function table lookup instead of a switch statement across syntax nodes. Also, the way TypeScript preserves information about a type in the true branch of a conditional type has been optimized.
- To optimize substitution types,
SubstitutionTypeobjects no longer contain the substitute property representing the effective substitution. Instead, they just contain the
TypeScript 5.0 is due as a beta release on January 24, 2023, with a release candidate set for February 28 and a production release slated to arrive March 14. TypeScript 4.8 shipped on August 25, bringing correctness and consistency improvements as well as file watching fixes.
Predecessor TypeScript 4.8 shipped on August 25, bringing correctness and consistency improvements as well as file watching fixes.