Async-Await Async function is same as a normal standard function. The function can have await expression which pauses the execution till it returns a promise and once it gets it, the execution continues. Await will only work if the function is async. Here is a working example on async and await.
As the error message says, add lib: es2015
to your tsconfig.json
// tsconfig.json
{
"compilerOptions": {
"lib": [ "es2015" ]
}
}
UPDATE: if this doesn't work for you, try this:
JetBrains IDE such as WebStorm, use its own implementation by default. Make sure you configure it to use TypeScript language service instead.
For Visual Studio, the project files and tsconfig.json
are mutually exclusive. You will need to configure your project directly.
https://github.com/Microsoft/TypeScript/issues/3983#issuecomment-123861491
Try this package which contains type definitions for es6-promise
npm install --save @types/es6-promise
If you are on VS, delete the tsconfig.json and right click the project in Solution Explorer, then click on Properties->TypeScript Build in General change the followings
ECMAScript version: ECMAScript 6
Module System: ES2015
For me the error occurred in my testing files inside src/tests
folder. Since I use ts-node
for testing the .ts
files directly, I excluded src/tests/*
in my tsconfig.json
. As soon as I deleted the line the error was gone (which makes sense in the end).
Just in case someone else is struggling with this in his testing files.
EDIT: Of course you need to configure your --lib
option correctly as outlined in the accepted answer. My tsconfig.json --lib
option works as following:
"lib": [
"es2018",
"dom"
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With