Fundamentals 16 min read

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.

Taobao Frontend Technology
Taobao Frontend Technology
Taobao Frontend Technology
What’s New in TypeScript 4.9 Beta? New Decorators, satisfies Operator, and More

TypeScript 4.9 beta was released on 2022‑09‑23. You can install the beta with npm install typescript@beta or 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 --experimentalDecorators and --emitDecoratorMetadata flags 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 satisfies operator, which lets you safely upcast a value while preserving the inferred type information.

Example:

const palette = { red: [255, 0, 0], green: "#00ff00", blue: [0, 0, 255] } satisfies Record<Colors, string | RGB>;

With satisfies the 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 moduleResolution is set to 'node', import paths normally omit the .ts extension. The new --noImplicitSuffix option (still tentative) forces the explicit .ts suffix.

Single‑file tsconfig directives

Comments such as // @ts-check or // @ts-nocheck can 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 in operator 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 === NaN is used, suggesting Number.isNaN(value) instead.

Other updates

Promise.resolve type improvement

The return type of Promise.resolve now 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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Type Safetydecoratorssatisfies operatorBeta
Taobao Frontend Technology
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.