Skip to content

Commit a6882d5

Browse files
5.5 stable updates
1 parent 8e87284 commit a6882d5

File tree

1 file changed

+7
-47
lines changed

1 file changed

+7
-47
lines changed

packages/documentation/copy/en/release-notes/TypeScript 5.5.md

+7-47
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ It now infers signatures with type predicates like `x is number` or `x is NonNul
107107
Type predicates have "if and only if" semantics.
108108
If a function returns `x is T`, then it means that:
109109

110-
1. If the function returns `true` then `x` is has type `T`.
110+
1. If the function returns `true` then `x` has the type `T`.
111111
2. If the function returns `false` then `x` does *not* have type `T`.
112112

113113
If you're expecting a type predicate to be inferred but it's not, then you may be running afoul of the second rule. This often comes up with "truthiness" checks:
@@ -183,7 +183,7 @@ function f1(obj: Record<string, unknown>, key: string) {
183183
In the above, neither `obj` nor `key` are ever mutated, so TypeScript can narrow the type of `obj[key]` to `string` after the `typeof` check.
184184
For more information, [see the implementing pull request here](https://github.com/microsoft/TypeScript/pull/57847).
185185

186-
## Type Imports in JSDoc
186+
## The JSDoc `@import` Tag
187187

188188
Today, if you want to import something only for type-checking in a JavaScript file, it is cumbersome.
189189
JavaScript developers can't simply import a type named `SomeType` if it's not there at runtime.
@@ -448,7 +448,7 @@ console.log(fruits.isSupersetOf(fruits));
448448
console.log(emptySet.isSupersetOf(fruits));
449449
```
450450

451-
We'd like to thank [Kevin Gibbons](https://github.com/bakkot) who not only proposed the feature in ECMAScript, but [also provided the declarations for `Set`, `ReadonlySet`, and `ReadonlySetLike` in TypeScript](https://github.com/microsoft/TypeScript/pull/57230)!
451+
We'd like to thank [Kevin Gibbons](https://github.com/bakkot) who not only co-championed the feature in ECMAScript, but [also provided the declarations for `Set`, `ReadonlySet`, and `ReadonlySetLike` in TypeScript](https://github.com/microsoft/TypeScript/pull/57230)!
452452

453453
## Isolated Declarations
454454

@@ -609,7 +609,9 @@ Keep an eye on this space, and feel free to provide us with feedback.
609609
We also feel it is worth calling out that `isolatedDeclarations` should be adopted on a case-by-case basis.
610610
There are some developer ergonomics that are lost when using `isolatedDeclarations`, and thus it may not be the right choice if your setup is not leveraging the two scenarios mentioned earlier.
611611
For others, the work on `isolatedDeclarations` has already uncovered many optimizations and opportunities to unlock different parallel build strategies.
612-
In the meantime, if you're willing to make the trade-offs, we believe `isolatedDeclarations` can be a powerful tool to speed up your build process once external tooling becomes available.
612+
In the meantime, if you're willing to make the trade-offs, we believe `isolatedDeclarations` can be a powerful tool to speed up your build process as external tooling becomes more widely available.
613+
614+
For more information, read up on the [Isolated Declarations: State of the Feature](https://github.com/microsoft/TypeScript/issues/58944) discussion on the TypeScript issue tracker.
613615

614616
### Credit
615617

@@ -784,7 +786,7 @@ One of the issues with these APIs is that TypeScript internally would perform a
784786
This was necessary to collect certain information which would later be used for the emit phase.
785787

786788
In TypeScript 5.5, we've found a way to avoid performing a full check, only lazily collecting this information as necessary, and `transpileModule` and `transpileDeclaration` both enable this functionality by default.
787-
As a result, tools that integrate with with these APIs, like [ts-loader](https://www.npmjs.com/package/ts-loader) with `transpileOnly` and [ts-jest](https://www.npmjs.com/package/ts-jest), should see a noticeable speedup.
789+
As a result, tools that integrate with these APIs, like [ts-loader](https://www.npmjs.com/package/ts-loader) with `transpileOnly` and [ts-jest](https://www.npmjs.com/package/ts-jest), should see a noticeable speedup.
788790
In our testing, [we generally witness around a 2x speed-up in build time using `transpileModule`](https://github.com/microsoft/TypeScript/pull/58364#issuecomment-2138580690).
789791

790792
### TypeScript Package Size Reduction
@@ -914,48 +916,6 @@ See also the [Flag Deprecation Plan](https://github.com/microsoft/TypeScript/iss
914916
Types generated for the DOM may have an impact on type-checking your codebase.
915917
For more information, [see the DOM updates for TypeScript 5.5](https://github.com/microsoft/TypeScript/pull/58211).
916918

917-
### Respecting File Extensions and `package.json` in Other Module Modes
918-
919-
Before Node.js implemented support for ECMAScript modules in v12, there was never a good way for TypeScript to know whether `.d.ts` files it found in `node_modules` represented JavaScript files authored as CommonJS or ECMAScript modules.
920-
When the vast majority of npm was CommonJS-only, this didn't cause many problems - if in doubt, TypeScript could just assume that everything behaved like CommonJS.
921-
Unfortunately, if that assumption was wrong it could allow unsafe imports:
922-
923-
```ts
924-
// node_modules/dep/index.d.ts
925-
export declare function doSomething(): void;
926-
927-
// index.ts
928-
// Okay if "dep" is a CommonJS module, but fails if
929-
// it's an ECMAScript module - even in bundlers!
930-
import dep from "dep";
931-
dep.doSomething();
932-
```
933-
934-
In practice, this didn't come up very often.
935-
But in the years since Node.js started supporting ECMAScript modules, the share of ESM on npm has grown.
936-
Fortunately, Node.js also introduced a mechanism that can help TypeScript determine if a file is an ECMAScript module or a CommonJS module: the `.mjs` and `.cjs` file extensions and the `package.json` `"type"` field.
937-
TypeScript 4.7 added support for understanding these indicators, as well as authoring `.mts` and `.cts` files;
938-
however, TypeScript would *only* read those indicators under `--module node16` and `--module nodenext`, so the unsafe import above was still a problem for anyone using `--module esnext` and `--moduleResolution bundler`, for example.
939-
940-
To solve this, TypeScript 5.5 reads and stores module format information encoded by file extensions and `package.json` `"type"` in *all* `module` modes, and uses it to resolve ambiguities like the one in the example above in all modes (except for `amd`, `umd`, and `system`).
941-
942-
A secondary effect of respecting this format information is that the format-specific TypeScript file extensions (`.mts` and `.cts`) or an explicitly set package.json `"type"` in your own project will *override* your `--module` option if it's set to `commonjs` or `es2015` through `esnext`.
943-
Previously, it was technically possible to produce CommonJS output into a `.mjs` file or vice versa:
944-
945-
```ts
946-
// main.mts
947-
export default "oops";
948-
949-
// $ tsc --module commonjs main.mts
950-
// main.mjs
951-
Object.defineProperty(exports, "__esModule", { value: true });
952-
exports.default = "oops";
953-
```
954-
955-
Now, `.mts` files (or `.ts` files in scope of a `package.json` with `"type": "module"`) never emit CommonJS output, and `.cts` files (or `.ts` files in scope of a package.json with `"type": "commonjs"`) never emit ESM output.
956-
957-
More details are available [on the change here](https://github.com/microsoft/TypeScript/pull/57896).
958-
959919
### Stricter Parsing for Decorators
960920

961921
Since TypeScript originally introduced support for decorators, the specified grammar for the proposal has been tightened up.

0 commit comments

Comments
 (0)