Skip to content

Commit cd504b1

Browse files
breyedjakebailey
andauthored
Fix scoping of destructuring annotation note (#2255)
Co-authored-by: Jake Bailey <[email protected]>
1 parent f9d0479 commit cd504b1

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -160,23 +160,21 @@ Now `xPos` and `yPos` are both definitely present within the body of `paintShape
160160

161161
> Note that there is currently no way to place type annotations within destructuring patterns.
162162
> This is because the following syntax already means something different in JavaScript.
163-
164-
```ts twoslash
165-
// @noImplicitAny: false
166-
// @errors: 2552 2304
167-
interface Shape {}
168-
declare function render(x: unknown);
169-
// ---cut---
170-
function draw({ shape: Shape, xPos: number = 100 /*...*/ }) {
171-
render(shape);
172-
render(xPos);
173-
}
174-
```
175-
176-
In an object destructuring pattern, `shape: Shape` means "grab the property `shape` and redefine it locally as a variable named `Shape`.
177-
Likewise `xPos: number` creates a variable named `number` whose value is based on the parameter's `xPos`.
178-
179-
Using [mapping modifiers](/docs/handbook/2/mapped-types.html#mapping-modifiers), you can remove `optional` attributes.
163+
>
164+
> ```ts twoslash
165+
> // @noImplicitAny: false
166+
> // @errors: 2552 2304
167+
> interface Shape {}
168+
> declare function render(x: unknown);
169+
> // ---cut---
170+
> function draw({ shape: Shape, xPos: number = 100 /*...*/ }) {
171+
> render(shape);
172+
> render(xPos);
173+
> }
174+
> ```
175+
>
176+
> In an object destructuring pattern, `shape: Shape` means "grab the property `shape` and redefine it locally as a variable named `Shape`.
177+
> Likewise `xPos: number` creates a variable named `number` whose value is based on the parameter's `xPos`.
180178
181179
### `readonly` Properties
182180

0 commit comments

Comments
 (0)