«   Previous tip Next tip   »

VS Code: Automatically convert your JavaScript promise chains to async/await

Last updated: 21st March 2023

Introduction

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

  1. Place the cursor next to the first letter of the first function name that encloses the promise chain.
  2. Enter Cmd + Shift + P and select Quick fix (You can also select the lightbulb icon that appears).
  3. Select Convert to async function.
  4. Now repeat this step on the next function, but select Convert all to async function.

This also works as expected with try/catch blocks.

«   Previous tip Next tip   »

Sign up to receive a developer tip, in the form of a gif, in your inbox each week