Repository: TypeScript
Issue: Bug: TS extract to constant in enclosing scope with lamda functions without curly braces
Labels: Bug,Help Wanted


Type: <b>Bug</b>

Hi,
when using the intellisense command `Extract to constant in enclosing scope` while inside a lambda function without curly braces and while having an argument of that lambda function selected, the new constant is created outside if the function which generates a build error.

For example:
```ts
const doSomething = (i: number) => (i + 2) * 5;
```
when selecting `i + 2` and running `Extract to constant in enclosing scope`, we get this:
```ts
const newLocal = i + 2;
const doSomething = (i: number) => (newLocal) * 5;
```
which is obviously wrong. We need to run `Add braces to arrow function` first, then the command above works correctly and generates
```ts
const doSomething = (i: number) => {
    const newLocal = i + 2;
    return (newLocal) * 5;
};
```

TS should please do this automatically, it bothers me every day ;-) Thanks in advance!

VS Code version: Code 1.81.0 (6445d93c81ebe42c4cbd7a60712e0b17d9463e97, 2023-08-02T12:37:13.485Z)
OS version: Windows_NT x64 10.0.19045
Modes:

<details>
<summary>System Info</summary>

|Item|Value|
|---|---|
|CPUs|Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz (12 x 3696)|
|GPU Status|2d_canvas: enabled<br>canvas_oop_rasterization: disabled_off<br>direct_rendering_display_compositor: disabled_off_ok<br>gpu_compositing: enabled<br>multiple_raster_threads: enabled_on<br>opengl: enabled_on<br>rasterization: enabled<br>raw_draw: disabled_off_ok<br>video_decode: enabled<br>video_encode: enabled<br>vulkan: disabled_off<br>webgl: enabled<br>webgl2: enabled<br>webgpu: enabled|
|Load (avg)|undefined|
|Memory (System)|31.96GB (16.72GB free)|
|Process Argv||
|Screen Reader|no|
|VM|0%|
</details><details><summary>Extensions (60)</summary>

Extension|Author (truncated)|Version
---|---|---
vscode-sql-formatter|adp|1.4.4
ng-template|Ang|16.1.4
vscode-intelephense-client|bme|1.9.5
dart-code|Dar|3.70.0
flutter|Dar|3.70.0
mustache|daw|1.1.1
vscode-eslint|dba|2.4.2
FreeMarker|dco|0.0.9
devicescript-vscode|dev|2.14.14
gitlens|eam|14.2.0
prettier-vscode|esb|10.1.0
php-intellisense|fel|2.3.14
auto-close-tag|for|0.5.14
auto-rename-tag|for|0.1.10
copilot|Git|1.101.317
copilot-labs|Git|0.14.884
vscode-github-actions|git|0.26.1
vscode-pull-request-github|Git|0.70.0
hcl|has|0.3.2
Angular2|joh|16.0.1
vscode-json5|mrm|1.0.0
vscode-docker|ms-|1.26.0
vscode-language-pack-de|MS-|1.81.2023080209
vscode-dotnet-runtime|ms-|1.6.0
playwright|ms-|1.0.15
isort|ms-|2023.10.1
python|ms-|2023.14.0
vscode-pylance|ms-|2023.8.10
remote-containers|ms-|0.304.0
remote-ssh|ms-|0.102.0
remote-ssh-edit|ms-|0.86.0
remote-wsl|ms-|0.81.0
vscode-remote-extensionpack|ms-|0.24.0
cpptools|ms-|1.16.3
hexeditor|ms-|1.9.12
remote-explorer|ms-|0.4.1
remote-server|ms-|1.4.0
vsliveshare|ms-|1.0.5877
vscode-streamdeck|nic|4.1.6
pico-w-go|pau|3.2.1
vscode-versionlens|pfl|1.5.0
platformio-ide|pla|3.3.1
prisma|Pri|5.1.0
sqlite-viewer|qwt|0.3.13
vscode-xml|red|0.26.1
vscode-sort-json|ric|1.20.0
markdown-preview-enhanced|shd|0.6.8
svg-preview|Sim|2.8.3
vscode-stripe|str|2.0.14
svelte-vscode|sve|107.9.0
even-better-toml|tam|0.19.2
simple-php-formatter|tob|0.0.1
sort-lines|Tyr|1.10.2
vscode-counter|uct|3.2.1
adb-interface-vscode|vin|0.22.4
keyoti-changeallendoflinesequence|vs-|0.0.3
vscode-icons|vsc|12.5.0
html-css-class-completion|Zig|1.20.0
linkerscript|Zix|1.0.3
vscode-proto3|zxh|0.5.5


</details>
<!-- generated by issue reporter -->