Promises to async/await in vscode

Viewed 6722
1 Answers

I didn't know it but i just tried in my vscode. When you just click or double click your function, a light bulb appears like in the videos you copied. Then you click on it and click "convert to async..."

  • You need to have javascript.validate.enable set true (vscode -> Preferences -> Settings) (or cmd-, in OSX).

  • I have version 1.30.0 (1.30.0). Check your version.

  • If none of this works maybe there is something wrong with your Promise. Try these examples...

TS:

function example(): Promise<boolean> {
  return fetch('https://stackoverflow.com').then( result => result.ok; );
}

JS:

function example() 
{ 
  return Promise.resolve(1) 
    .then((value) => { 
      console.log(value) 
    }) 
    .catch(err => { 
      console.log(err); 
    })
}
Related