Skip to content

Commit 236f0f8

Browse files
Sync with TypeScript-Website @ 80d3fc1 (#60)
2 parents 572fba1 + ebdcca3 commit 236f0f8

File tree

45 files changed

+289
-105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+289
-105
lines changed

.changeset/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3-
"changelog": "@changesets/cli/changelog",
3+
"changelog": ["@changesets/changelog-github", { "repo": "microsoft/TypeScript-Website" }],
44
"commit": false,
55
"fixed": [],
66
"linked": [],

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"pnpm": ">=9"
77
},
88
"devDependencies": {
9+
"@changesets/changelog-github": "^0.5.0",
910
"@changesets/cli": "^2.27.5",
1011
"@oss-docs/sync": "^1.1.4",
1112
"@types/express": "^4.17.6",

packages/ata/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# @typescript/ata
22

3+
## 0.9.6
4+
5+
### Patch Changes
6+
7+
- [#2977](https://github.com/microsoft/TypeScript-Website/pull/2977) [`7691811`](https://github.com/microsoft/TypeScript-Website/commit/7691811c180e3b352cf4e888387d1edfc10f5252) Thanks [@curran](https://github.com/curran)! - Widen typescript peer dependency range
8+
9+
- [#3000](https://github.com/microsoft/TypeScript-Website/pull/3000) [`71776ae`](https://github.com/microsoft/TypeScript-Website/commit/71776aecc1b56289ab56d240a9272ce83686ef1a) Thanks [@antfu](https://github.com/antfu)! - Handle `.d.cts` and `.d.mts` files
10+
11+
- [#3002](https://github.com/microsoft/TypeScript-Website/pull/3002) [`fd776c0`](https://github.com/microsoft/TypeScript-Website/commit/fd776c05bb8fa9c897d18fa237af39ae8da03a7c) Thanks [@antfu](https://github.com/antfu)! - Fix return type of `setupTypeAcquisition`
12+
313
## 0.9.5
414

515
### Patch Changes

packages/ata/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@typescript/ata",
3-
"version": "0.9.5",
3+
"version": "0.9.6",
44
"license": "MIT",
55
"homepage": "https://github.com/microsoft/TypeScript-Website",
66
"repository": {
@@ -27,6 +27,6 @@
2727
"jest": "^29.5.0"
2828
},
2929
"peerDependencies": {
30-
"typescript": "^4.4.4"
30+
"typescript": ">=4.4.4"
3131
}
3232
}

packages/ata/src/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const setupTypeAcquisition = (config: ATABootstrapConfig) => {
7171
const treesOnly = trees.filter(t => !("error" in t)) as NPMTreeMeta[]
7272

7373
// These are the modules which we can grab directly
74-
const hasDTS = treesOnly.filter(t => t.files.find(f => f.name.endsWith(".d.ts")))
74+
const hasDTS = treesOnly.filter(t => t.files.find(f => isDtsFile(f.name)))
7575
const dtsFilesFromNPM = hasDTS.map(t => treeToDTSFiles(t, `/node_modules/${t.moduleName}`))
7676

7777
// These are ones we need to look on DT for (which may not be there, who knows)
@@ -142,7 +142,7 @@ function treeToDTSFiles(tree: NPMTreeMeta, vfsPrefix: string) {
142142
const dtsRefs: ATADownload[] = []
143143

144144
for (const file of tree.files) {
145-
if (file.name.endsWith(".d.ts")) {
145+
if (isDtsFile(file.name)) {
146146
dtsRefs.push({
147147
moduleName: tree.moduleName,
148148
moduleVersion: tree.version,
@@ -170,7 +170,7 @@ export const getReferencesForModule = (ts: typeof import("typescript"), code: st
170170
const references = meta.referencedFiles
171171
.concat(meta.importedFiles)
172172
.concat(meta.libReferenceDirectives)
173-
.filter(f => !f.fileName.endsWith(".d.ts"))
173+
.filter(f => !isDtsFile(f.fileName))
174174
.filter(d => !libMap.has(d.fileName))
175175

176176
return references.map(r => {
@@ -268,3 +268,7 @@ function getDTName(s: string) {
268268
}
269269
return s
270270
}
271+
272+
function isDtsFile(file: string) {
273+
return /\.d\.([^\.]+\.)?[cm]?ts$/i.test(file)
274+
}

packages/ata/src/userFacingTypes.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type ModuleMeta = { state: "loading" }
3333
* basically exported for tests and should be considered
3434
* implementation details by consumers.
3535
*/
36-
export const setupTypeAcquisition: (config: ATABootstrapConfig) => (initialSourceFile: string) => void
36+
export const setupTypeAcquisition: (config: ATABootstrapConfig) => (initialSourceFile: string) => Promise<void>
3737

3838
interface Logger {
3939
log: (...args: any[]) => void

packages/documentation/copy/en/get-started/TS for Functional Programmers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ TypeScript has corresponding primitive types for the built-in types:
7676
| -------------- | ------------------------------------------------------------------------------- |
7777
| `unknown` | the top type. |
7878
| `never` | the bottom type. |
79-
| object literal | eg `{ property: Type }` |
80-
| `void` | for functions with no documented return value |
79+
| object literal | e.g. `{ property: Type }` |
80+
| `void` | for functions with no documented return value |
8181
| `T[]` | mutable arrays, also written `Array<T>` |
8282
| `[T, T]` | tuples, which are fixed-length but mutable |
8383
| `(t: T) => U` | functions |

packages/documentation/copy/en/handbook-v2/Classes.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,14 @@ class Point {
150150

151151
```ts twoslash
152152
class Point {
153-
// Overloads
154-
constructor(x: number, y: string);
155-
constructor(s: string);
156-
constructor(xs: any, y?: any) {
157-
// TBD
153+
x: number = 0;
154+
y: number = 0;
155+
156+
// Constructor overloads
157+
constructor(x: number, y: number);
158+
constructor(xy: string);
159+
constructor(x: string | number, y: number = 0) {
160+
// Code logic here
158161
}
159162
}
160163
```
@@ -250,7 +253,6 @@ TypeScript has some special inference rules for accessors:
250253

251254
- If `get` exists but no `set`, the property is automatically `readonly`
252255
- If the type of the setter parameter is not specified, it is inferred from the return type of the getter
253-
- Getters and setters must have the same [Member Visibility](#member-visibility)
254256

255257
Since [TypeScript 4.3](https://devblogs.microsoft.com/typescript/announcing-typescript-4-3/), it is possible to have accessors with different types for getting and setting.
256258

packages/documentation/copy/en/handbook-v2/Everyday Types.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ You'll learn more about these concepts in later chapters, so don't worry if you
469469
- Type aliases may not participate [in declaration merging, but interfaces can](/play?#code/PTAEEEDtQS0gXApgJwGYEMDGjSfdAIx2UQFoB7AB0UkQBMAoEUfO0Wgd1ADd0AbAK6IAzizp16ALgYM4SNFhwBZdAFtV-UAG8GoPaADmNAcMmhh8ZHAMMAvjLkoM2UCvWad+0ARL0A-GYWVpA29gyY5JAWLJAwGnxmbvGgALzauvpGkCZmAEQAjABMAMwALLkANBl6zABi6DB8okR4Jjg+iPSgABboovDk3jjo5pbW1d6+dGb5djLwAJ7UoABKiJTwjThpnpnGpqPBoTLMAJrkArj4kOTwYmycPOhW6AR8IrDQ8N04wmo4HHQCwYi2Waw2W1S6S8HX8gTGITsQA).
470470
- Interfaces may only be used to [declare the shapes of objects, not rename primitives](/play?#code/PTAEAkFMCdIcgM6gC4HcD2pIA8CGBbABwBtIl0AzUAKBFAFcEBLAOwHMUBPQs0XFgCahWyGBVwBjMrTDJMAshOhMARpD4tQ6FQCtIE5DWoixk9QEEWAeV37kARlABvaqDegAbrmL1IALlAEZGV2agBfampkbgtrWwMAJlAAXmdXdy8ff0Dg1jZwyLoAVWZ2Lh5QVHUJflAlSFxROsY5fFAWAmk6CnRoLGwmILzQQmV8JmQmDzI-SOiKgGV+CaYAL0gBBdyy1KCQ-Pn1AFFplgA5enw1PtSWS+vCsAAVAAtB4QQWOEMKBuYVUiVCYvYQsUTQcRSBDGMGmKSgAAa-VEgiQe2GLgKQA).
471471
- Interface names will [_always_ appear in their original form](/play?#code/PTAEGEHsFsAcEsA2BTATqNrLusgzngIYDm+oA7koqIYuYQJ56gCueyoAUCKAC4AWHAHaFcoSADMaQ0PCG80EwgGNkALk6c5C1EtWgAsqOi1QAb06groEbjWg8vVHOKcAvpokshy3vEgyyMr8kEbQJogAFND2YREAlOaW1soBeJAoAHSIkMTRmbbI8e6aPMiZxJmgACqCGKhY6ABGyDnkFFQ0dIzMbBwCwqIccabcYLyQoKjIEmh8kwN8DLAc5PzwwbLMyAAeK77IACYaQSEjUWY2Q-YAjABMAMwALA+gbsVjNXW8yxySoAADaAA0CCaZbPh1XYqXgOIY0ZgmcK0AA0nyaLFhhGY8F4AHJmEJILCWsgZId4NNfIgGFdcIcUTVfgBlZTOWC8T7kAJ42G4eT+GS42QyRaYbCgXAEEguTzeXyCjDBSAAQSE8Ai0Xsl0K9kcziExDeiQs1lAqSE6SyOTy0AKQ2KHk4p1V6s1OuuoHuzwArMagA) in error messages, but _only_ when they are used by name.
472+
- Using interfaces with `extends` [can often be more performant for the compiler](https://github.com/microsoft/TypeScript/wiki/Performance#preferring-interfaces-over-intersections) than type aliases with intersections
472473

473474
For the most part, you can choose based on personal preference, and TypeScript will tell you if it needs something to be the other kind of declaration. If you would like a heuristic, use `interface` until you need to use features from `type`.
474475

packages/documentation/copy/en/handbook-v2/Object Types.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ This index signature states that when a `StringArray` is indexed with a `number`
274274
Only some types are allowed for index signature properties: `string`, `number`, `symbol`, template string patterns, and union types consisting only of these.
275275

276276
<details>
277-
<summary>It is possible to support both types of indexers...</summary>
278-
<p>It is possible to support both types of indexers, but the type returned from a numeric indexer must be a subtype of the type returned from the string indexer. This is because when indexing with a <code>number</code>, JavaScript will actually convert that to a <code>string</code> before indexing into an object. That means that indexing with <code>100</code> (a <code>number</code>) is the same thing as indexing with <code>"100"</code> (a <code>string</code>), so the two need to be consistent.</p>
277+
<summary>It is possible to support multiple types of indexers...</summary>
278+
<p>It is possible to support multiple types of indexers. Note that when using both `number` and `string` indexers, the type returned from a numeric indexer must be a subtype of the type returned from the string indexer. This is because when indexing with a <code>number</code>, JavaScript will actually convert that to a <code>string</code> before indexing into an object. That means that indexing with <code>100</code> (a <code>number</code>) is the same thing as indexing with <code>"100"</code> (a <code>string</code>), so the two need to be consistent.</p>
279279

280280
```ts twoslash
281281
// @errors: 2413

packages/documentation/copy/en/handbook-v2/Type Manipulation/Generics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ let myIdentity: <Type>(arg: Type) => Type = identity;
152152
We could also have used a different name for the generic type parameter in the type, so long as the number of type variables and how the type variables are used line up.
153153

154154
```ts twoslash
155-
function identity<Input>(arg: Input): Input {
155+
function identity<Type>(arg: Type): Type {
156156
return arg;
157157
}
158158

packages/documentation/copy/en/javascript/JSDoc Reference.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,7 @@ The following tags have open issues to support them:
827827

828828
- `@memberof` ([issue #7237](https://github.com/Microsoft/TypeScript/issues/7237))
829829
- `@yields` ([issue #23857](https://github.com/Microsoft/TypeScript/issues/23857))
830+
- `@member` ([issue #56674](https://github.com/microsoft/TypeScript/issues/56674))
830831

831832
### Legacy type synonyms
832833

@@ -852,4 +853,4 @@ So the compiler treats these types as synonyms based on usage in old JSDoc:
852853
The last four aliases are turned off when `noImplicitAny: true`:
853854

854855
- `object` and `Object` are built-in types, although `Object` is rarely used.
855-
- `array` and `promise` are not built-in, but might be declared somewhere in your program.
856+
- `array` and `promise` are not built-in, but might be declared somewhere in your program.

packages/documentation/copy/en/modules-reference/Reference.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,12 @@ The detected module format of input `.ts`/`.tsx`/`.mts`/`.cts` files determines
231231
The emit format of each file is determined by the [detected module format](#module-format-detection) of each file. ESM emit is similar to [`--module esnext`](#es2015-es2020-es2022-esnext), but has a special transformation for `import x = require("...")`, which is not allowed in `--module esnext`:
232232

233233
```ts
234+
// @Filename: main.ts
234235
import x = require("mod");
235236
```
236237

237238
```js
239+
// @Filename: main.js
238240
import { createRequire as _createRequire } from "module";
239241
const __require = _createRequire(import.meta.url);
240242
const x = __require("mod");
@@ -243,11 +245,13 @@ const x = __require("mod");
243245
CommonJS emit is similar to [`--module commonjs`](#commonjs), but dynamic `import()` calls are not transformed. Emit here is shown with `esModuleInterop` enabled:
244246
245247
```ts
248+
// @Filename: main.ts
246249
import fs from "fs"; // transformed
247250
const dynamic = import("mod"); // not transformed
248251
```
249252
250253
```js
254+
// @Filename: main.js
251255
"use strict";
252256
var __importDefault = (this && this.__importDefault) || function (mod) {
253257
return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -322,6 +326,7 @@ export default "default export";
322326
#### Examples
323327
324328
```ts
329+
// @Filename: main.ts
325330
import x, { y, z } from "mod";
326331
import * as mod from "mod";
327332
const dynamic = import("mod");
@@ -332,6 +337,7 @@ export default "default export";
332337
```
333338
334339
```js
340+
// @Filename: main.js
335341
import x, { y, z } from "mod";
336342
import * as mod from "mod";
337343
const dynamic = import("mod");
@@ -355,6 +361,7 @@ export default "default export";
355361
> Output is shown with `esModuleInterop: false`.
356362
357363
```ts
364+
// @Filename: main.ts
358365
import x, { y, z } from "mod";
359366
import * as mod from "mod";
360367
const dynamic = import("mod");
@@ -365,6 +372,7 @@ export default "default export";
365372
```
366373
367374
```js
375+
// @Filename: main.js
368376
"use strict";
369377
Object.defineProperty(exports, "__esModule", { value: true });
370378
exports.e1 = void 0;
@@ -378,6 +386,7 @@ exports.default = "default export";
378386
```
379387
380388
```ts
389+
// @Filename: main.ts
381390
import mod = require("mod");
382391
console.log(mod);
383392

@@ -388,6 +397,7 @@ export = {
388397
```
389398
390399
```js
400+
// @Filename: main.js
391401
"use strict";
392402
const mod = require("mod");
393403
console.log(mod);
@@ -407,6 +417,7 @@ module.exports = {
407417
#### Examples
408418
409419
```ts
420+
// @Filename: main.ts
410421
import x, { y, z } from "mod";
411422
import * as mod from "mod";
412423
const dynamic = import("mod");
@@ -417,6 +428,7 @@ export default "default export";
417428
```
418429
419430
```js
431+
// @Filename: main.js
420432
System.register(["mod"], function (exports_1, context_1) {
421433
"use strict";
422434
var mod_1, mod, dynamic, e1;
@@ -450,6 +462,7 @@ System.register(["mod"], function (exports_1, context_1) {
450462
#### Examples
451463
452464
```ts
465+
// @Filename: main.ts
453466
import x, { y, z } from "mod";
454467
import * as mod from "mod";
455468
const dynamic = import("mod");
@@ -460,6 +473,7 @@ export default "default export";
460473
```
461474
462475
```js
476+
// @Filename: main.js
463477
define(["require", "exports", "mod", "mod"], function (require, exports, mod_1, mod) {
464478
"use strict";
465479
Object.defineProperty(exports, "__esModule", { value: true });
@@ -484,6 +498,7 @@ define(["require", "exports", "mod", "mod"], function (require, exports, mod_1,
484498
#### Examples
485499
486500
```ts
501+
// @Filename: main.ts
487502
import x, { y, z } from "mod";
488503
import * as mod from "mod";
489504
const dynamic = import("mod");
@@ -494,6 +509,7 @@ export default "default export";
494509
```
495510
496511
```js
512+
// @Filename: main.js
497513
(function (factory) {
498514
if (typeof module === "object" && typeof module.exports === "object") {
499515
var v = factory(require, exports);
@@ -985,7 +1001,7 @@ import foo = require("pkg/dist/foo"); // ✅ require, no extension needed
9851001

9861002
#### package.json `"imports"` and self-name imports
9871003

988-
When `moduleResolution` is set to `node16`, `nodenext`, or `bundler`, and `resolvePackageJsonImports` is not disabled, TypeScript will attempt to resolve import paths beginning with `#` through the the `"imports"` field of the nearest ancestor package.json of the importing file. Similarly, when [package.json `"exports"` lookups](#packagejson-exports) are enabled, TypeScript will attempt to resolve import paths beginning with the current package name—that is, the value in the `"name"` field of the nearest ancestor package.json of the importing file—through the `"exports"` field of that package.json. Both of these features allow files in a package to import other files in the same package, replacing a relative import path.
1004+
When `moduleResolution` is set to `node16`, `nodenext`, or `bundler`, and `resolvePackageJsonImports` is not disabled, TypeScript will attempt to resolve import paths beginning with `#` through the `"imports"` field of the nearest ancestor package.json of the importing file. Similarly, when [package.json `"exports"` lookups](#packagejson-exports) are enabled, TypeScript will attempt to resolve import paths beginning with the current package name—that is, the value in the `"name"` field of the nearest ancestor package.json of the importing file—through the `"exports"` field of that package.json. Both of these features allow files in a package to import other files in the same package, replacing a relative import path.
9891005

9901006
TypeScript follows Node.js’s resolution algorithm for [`"imports"`](https://nodejs.org/api/packages.html#subpath-imports) and [self references](https://nodejs.org/api/packages.html#self-referencing-a-package-using-its-name) exactly up until a file path is resolved. At that point, TypeScript’s resolution algorithm forks based on whether the package.json containing the `"imports"` or `"exports"` being resolved belongs to a `node_modules` dependency or the local project being compiled (i.e., its directory contains the tsconfig.json file for the project that contains the importing file):
9911007

packages/documentation/copy/en/reference/Utility Types.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@ Constructs an object type whose property keys are `Keys` and whose property valu
140140
##### Example
141141

142142
```ts twoslash
143+
type CatName = "miffy" | "boris" | "mordred";
144+
143145
interface CatInfo {
144146
age: number;
145147
breed: string;
146148
}
147149

148-
type CatName = "miffy" | "boris" | "mordred";
149-
150150
const cats: Record<CatName, CatInfo> = {
151151
miffy: { age: 10, breed: "Persian" },
152152
boris: { age: 5, breed: "Maine Coon" },

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ type T7 = T4<A, B>; // "a" | "b"
328328
## Better handling for namespace patterns in `.js` files
329329

330330
TypeScript 2.8 adds support for understanding more namespace patterns in `.js` files.
331-
Empty object literals declarations on top level, just like functions and classes, are now recognized as as namespace declarations in JavaScript.
331+
Empty object literals declarations on top level, just like functions and classes, are now recognized as namespace declarations in JavaScript.
332332

333333
```js
334334
var ns = {}; // recognized as a declaration for a namespace `ns`

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ if (!obj.prop) {
417417
}
418418
```
419419

420-
[Try running the following example](https://www.typescriptlang.org/play?ts=Nightly#code/MYewdgzgLgBCBGArGBeGBvAsAKBnmA5gKawAOATiKQBQCUGO+TMokIANkQHTsgHUAiYlChFyMABYBDCDHIBXMANoBuHI2Z4A9FpgAlIqXZTgRGAFsiAQg2byJeeTAwAslKgSu5KWAAmIczoYAB4YAAYuAFY1XHwAXwAaWxgIEhgKKmoAfQA3KXYALhh4EA4iH3osWM1WCDKePkFUkTFJGTlFZRimOJw4mJwAM0VgKABLcBhB0qCqplr63n4BcjGCCVgIMd8zIjz2eXciXy7k+yhHZygFIhje7BwFzgblgBUJMdlwM3yAdykAJ6yBSQGAeMzNUTkU7YBCILgZUioOBIBGUJEAHwxUxmqnU2Ce3CWgnenzgYDMACo6pZxpYIJSOqDwSkSFCYXC0VQYFi0NMQHQVEA) to see how that differs from _always_ performing the assignment.
420+
[Try running the following example](https://www.typescriptlang.org/play?ts=next#code/MYewdgzgLgBCBGArGBeGBvAsAKBnmA5gKawAOATiKQBQCUGO+TMokIANkQHTsgHUAiYlChFyMABYBDCDHIBXMANoBuHI2Z4A9FpgAlIqXZTgRGAFsiAQg2byJeeTAwAslKgSu5KWAAmIczoYAB4YAAYuAFY1XHwAXwAaWxgIEhgKKmoAfQA3KXYALhh4EA4iH3osWM1WCDKePkFUkTFJGTlFZRimOJw4mJwAM0VgKABLcBhB0qCqplr63n4BcjGCCVgIMd8zIjz2eXciXy7k+yhHZygFIhje7BwFzgblgBUJMdlwM3yAdykAJ6yBSQGAeMzNUTkU7YBCILgZUioOBIBGUJEAHwxUxmqnU2Ce3CWgnenzgYDMACo6pZxpYIJSOqDwSkSFCYXC0VQYFi0NMQHQVEA) to see how that differs from _always_ performing the assignment.
421421

422422
```ts twoslash
423423
const obj = {

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ const palette = {
2020
// ^^^^ sacrebleu - we've made a typo!
2121
};
2222

23-
// We want to be able to use array methods on 'red'...
24-
const redComponent = palette.red.at(0);
25-
26-
// or string methods on 'green'...
23+
// We want to be able to use string methods on 'green'...
2724
const greenNormalized = palette.green.toUpperCase();
2825
```
2926

@@ -42,8 +39,9 @@ const palette: Record<Colors, string | RGB> = {
4239
// ~~~~ The typo is now correctly detected
4340
};
4441

45-
// But we now have an undesirable error here - 'palette.red' "could" be a string.
46-
const redComponent = palette.red.at(0);
42+
// But we now have an undesirable error here - 'palette.green' "could" be of type RGB and
43+
// property 'toUpperCase' does not exist on type 'string | RGB'.
44+
const greenNormalized = palette.green.toUpperCase();
4745
```
4846

4947
The new `satisfies` operator lets us validate that the type of an expression matches some type, without changing the resulting type of that expression.
@@ -61,8 +59,7 @@ const palette = {
6159
// ~~~~ The typo is now caught!
6260
} satisfies Record<Colors, string | RGB>;
6361

64-
// Both of these methods are still accessible!
65-
const redComponent = palette.red.at(0);
62+
// toUpperCase() method is still accessible!
6663
const greenNormalized = palette.green.toUpperCase();
6764
```
6865

0 commit comments

Comments
 (0)