相关疑难解决方法(0)

typescript:error TS2693:'Promise'只引用一个类型,但在这里被用作值

我正在尝试使用Typescript作为我的AWS Lambda,我在使用promises时遇到以下错误.

error TS2693: 'Promise' only refers to a type, but is being used as a value here.

我尝试在代码中使用以下变体

使用Promise构造函数

responsePromise = new Promise((resolve, reject) => {
                    return reject(new Error(`missing is needed data`))
                })
Run Code Online (Sandbox Code Playgroud)

使用Promise.reject

responsePromise = Promise.reject(new Error(`Unsupported method "${request.httpMethod}"`));
Run Code Online (Sandbox Code Playgroud)

版本

以下是我的dev依赖项中的版本:

"typescript": "^2.2.2"
"@types/aws-lambda": "0.0.9",
"@types/core-js": "^0.9.40",
"@types/node": "^7.0.12",
Run Code Online (Sandbox Code Playgroud)

tsconfig.json的内容

{
    "compileOnSave": true,
    "compilerOptions": {
        "module": "commonjs",
        // "typeRoots" : ["./typings", "./node_modules/@types"],
        "target": "es5",
        // "types" : [ "core-js" ],
        "noImplicitAny": true,
        "strictNullChecks": true,
        "allowJs": true,
        "noEmit": true, …
Run Code Online (Sandbox Code Playgroud)

javascript promise typescript

137
推荐指数
9
解决办法
8万
查看次数

标签 统计

javascript ×1

promise ×1

typescript ×1