简体   繁体   English

“承诺”仅指类型,但在此处用作值

[英]'Promise' only refers to a type, but is being used as a value here

Error: [js] 'Promise' only refers to a type, but is being used as a value here. 错误:[js]'Promise'仅指类型,但在此处被用作值。

I have set "checkJS": true and "jsx": "react" in jsconfig.json. 我在"checkJS": true设置了"checkJS": true"jsx": "react" This is not for ts. 这不适用于ts。

async function readAsArrayBuffer(blob) {
return new Promise((resolve, reject) => {
         let reader = new FileReader();
         // @ts-ignore
        reader.addEventListener('load', e => resolve((e.target).result));
         // @ts-ignore
        reader.addEventListener('error', e => reject((e.target).error));
        reader.readAsArrayBuffer(blob);
    });
}

Script ofcourse working good. 课程脚本运作良好。

How do I fix this unnecessary error? 如何解决此不必要的错误?

I expect you need to target es6 or use a polyfill. 我希望您需要定位es6或使用polyfill。 I don't use VisualStudio but it looks like the following addition to your config might enable es6: 我不使用VisualStudio,但看起来您配置中的以下新增内容可能会启用es6:

{
    "compilerOptions": { "target": "ES6" },
    //....
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 打字稿:错误 TS2693:“Promise”仅指一种类型,但在此处用作值 - typescript: error TS2693: 'Promise' only refers to a type, but is being used as a value here 导出时类型“仅指一种类型,但在此处用作值” - Type “only refers to a type, but is being used as a value here” when exporting 'MapEditServiceConfig'仅引用类型,但在此处用作值 - 'MapEditServiceConfig' only refers to a type, but is being used as a value here “'输出'仅指一种类型,但在此处使用了一个值”错误 - "'Output' only refers to a type, but is being used a value here" error “post”仅指一种类型,但在此处用作值 - 'post' only refers to a type, but is being used as a value here 元素指的是一个值,但在这里被用作类型 - element refers to a value, but is being used as a type here 'ItemIsLoading'on指的是一种类型,但此处被用作值 - 'ItemIsLoading' on refers to a type, but is being used as a value here 指的是一个值,但在这里被用作一个类型 - refers to a value, but is being used as a type here IFormContext 只引用一个类型,但在这里用作一个值 - IFormContext only refers to a type, but is used as a value here 打字稿错误:'RRule' 仅引用类型,但在此处用作命名空间 - typescript error: 'RRule' only refers to a type, but is being used as a namespace here
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM