Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions packages/documentation/copy/en/release-notes/TypeScript 4.9.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ const palette = {
// ^^^^ sacrebleu - we've made a typo!
};

// We want to be able to use array methods on 'red'...
const redComponent = palette.red.at(0);

// or string methods on 'green'...
// We want to be able to use string methods on 'green'...
const greenNormalized = palette.green.toUpperCase();
```

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

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

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

// Both of these methods are still accessible!
const redComponent = palette.red.at(0);
// toUpperCase() methode is still accessible!
const greenNormalized = palette.green.toUpperCase();
```

Expand Down