What’s New in TypeScript 4.9 Beta? New Decorators, satisfies Operator, and More
TypeScript 4.9 beta introduces ECMAScript‑aligned decorators, a new satisfies operator for safer upcasting, support for .ts import extensions, per‑file tsconfig directives, enhanced in‑operator narrowing, NaN equality warnings, updated Promise.resolve typing, and full retention of JavaScript imports, with installation instructions and migration notes.
TypeScript 4.9 beta was released on 2022‑09‑23. You can install the beta with
npm install typescript@betaor update the built‑in TypeScript support in VS Code via the JavaScript and TypeScript Nightly extension.
ECMAScript‑aligned decorators
Support for the new ECMAScript decorator proposal is postponed to TypeScript 5.0; the existing
--experimentalDecoratorsand
--emitDecoratorMetadataflags remain for the legacy decorators.
The beta version usually does not differ much from the final release.
satisfies operator
The most important new feature in 4.9 is the
satisfiesoperator, which lets you safely upcast a value while preserving the inferred type information.
Example:
<code>const palette = { red: [255, 0, 0], green: "#00ff00", blue: [0, 0, 255] } satisfies Record<Colors, string | RGB>;</code>With
satisfiesthe variable is constrained to the declared type but still retains the precise property types for subsequent usage.
The name satisfies was chosen over the alternative implements to avoid conflict with the existing JavaScript keyword.
Import paths with .ts suffix
When
moduleResolutionis set to
'node', import paths normally omit the
.tsextension. The new
--noImplicitSuffixoption (still tentative) forces the explicit
.tssuffix.
Single‑file tsconfig directives
Comments such as
// @ts-checkor
// @ts-nocheckcan now appear at the top of a file to adjust checking behavior. The beta also adds support for per‑file configuration via
// @ts-config …directives.
Unlisted property narrowing
The
inoperator now narrows the left‑hand side to
object & Record<"userId", unknown>, allowing type guards for properties that are not listed in the original type.
NaN equality check
TypeScript now warns when
value === NaNis used, suggesting
Number.isNaN(value)instead.
Other updates
Promise.resolve type improvement
The return type of
Promise.resolvenow uses
Awaited<T>, providing a more accurate resolved type.
Full retention of JavaScript imports
Import statements in JavaScript files are now kept even when they are used only for JSDoc type annotations.
The article concludes with a note that TypeScript 5.0 beta will continue the rollout of these features.
Taobao Frontend Technology
The frontend landscape is constantly evolving, with rapid innovations across familiar languages. Like us, your understanding of the frontend is continually refreshed. Join us on Taobao, a vibrant, all‑encompassing platform, to uncover limitless potential.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.