VS Code: Automatically convert your JavaScript promise chains to async/await
Last updated: 21st March 2023Introduction
Visual Studio Code can convert your long chains of Promise.then()
's into async/await! This works with JavaScript or TypeScript.
How to use this feature
- Place the cursor next to the first letter of the first function name that encloses the promise chain.
- Enter
Cmd + Shift + P
and selectQuick fix
(You can also select the lightbulb icon that appears). - Select Convert to async function.
- Now repeat this step on the next function, but select Convert all to async function.
This also works as expected with try/catch
blocks.