I'm trying to add an async function in a TypeScript project. The code looks like this:
chrome.tabs.onUpdated.addListener(async (id, c, t) => { ... });
TypeScript complains:
error TS2705: An async function or method in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your --lib option
When I add lib: ['es2015']
to tsconfig, TypeScript starts complaining about all calls to console.log
saying that console is undefined.
The default libs for es5
are DOM,ES5
, so if you specify es2015
you will also need to add dom
explicitly as console
is defined in the dom
library. Sample tsconfig.json
:
{
"compilerOptions": {
"target": "es5",
"lib": [
"es2015",
"dom"
]
}
}
Typescript has a modular approach to the default libraries, so you can include only what is available based on your environment.
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