From 51854837173ac87b7db9ac7968962d8d227ed3eb Mon Sep 17 00:00:00 2001 From: Marius <90092216+mariusgau@users.noreply.github.com> Date: Wed, 27 Mar 2024 19:45:08 +0100 Subject: [PATCH] Improve first Example of "The satisfies Operator" in TypeScript 4.9 release notes --- .../copy/en/release-notes/TypeScript 4.9.md | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/documentation/copy/en/release-notes/TypeScript 4.9.md b/packages/documentation/copy/en/release-notes/TypeScript 4.9.md index 5033ae8a9b12..1a428995ed94 100644 --- a/packages/documentation/copy/en/release-notes/TypeScript 4.9.md +++ b/packages/documentation/copy/en/release-notes/TypeScript 4.9.md @@ -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(); ``` @@ -42,8 +39,9 @@ const palette: Record = { // ~~~~ 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. @@ -61,8 +59,7 @@ const palette = { // ~~~~ The typo is now caught! } satisfies Record; -// Both of these methods are still accessible! -const redComponent = palette.red.at(0); +// toUpperCase() methode is still accessible! const greenNormalized = palette.green.toUpperCase(); ```