我知道这个问题之前被问过,但解决方案并不能解决我的问题。
所以我想再问一遍。因为我尝试过 ES5、ES6、ES2018、ES2015、ES2015.promise 等..
背景.js
async function run() {
setInterval(()=>{
console.log("Hello world");
},3000);
}
async function getTab() {
const tabs = await chrome.tabs.query({});
return tabs[0];
}
setInterval(async function(){
const tab = await getTab();
console.log(tab);
chrome.scripting.executeScript(
{
target: {tabId: tab.id, allFrames: true},
func: run,
},
(injectionResults) => {
console.log("what is happening here",injectionResults);
});
},5000);
tsconfig.json
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"sourceMap": true,
"outDir": "out",
"lib": [ "es2018", "dom" ]
}
}
tsc背景.ts
出现此错误
error TS2468: Cannot find global value 'Promise'.
Background.ts:7:16 - 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.
7 async function run() {
~~~
Background.ts:20:13 - 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.
20 setInterval(async function(){
tsc 命令可能没有获取 tsconfig.json 文件。 我认为当您在命令行中指定源文件时会发生这种情况。 当我运行
tsc index.ts
时它显示错误,但当我只是运行 tsc
时则没有。
我不知道不同的文件名会如何改变。
嗨,独奏抓取扩展“JavaScript 和 TypeScript Nightly” “ en vsc y desaparecio