TypeScript complains without lib

I am trying to add an asynchronous function to a TypeScript project. The code is as follows:

chrome.tabs.onUpdated.addListener(async (id, c, t) => { ... }); 

TypeScript complains:

TS2705 error: async function or method in ES5 / ES3 requires the constructor "Promise". Make sure you have a declaration for the "Promise" constructor or specify "ES2015" in your -lib option

When I add lib: ['es2015'] to tsconfig, TypeScript starts complaining about all calls to console.log , saying that the console is undefined.

+5
source share
1 answer

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. Example tsconfig.json :

 { "compilerOptions": { "target": "es5", "lib": [ "es2015", "dom" ] } } 

Typescript has a modular approach to libraries by default, so you can only include what is available based on your environment.

+4
source

Source: https://habr.com/ru/post/1273852/


All Articles