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

标签 javascript typescript promise

我正在尝试将 Typescript 用于我的 AWS Lambda,但我在使用 promises 时遇到以下错误。

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

I tried using the following variations in the code

Using the Promise constructor

responsePromise = new Promise((resolve, reject) => {
                    return reject(new Error(`missing is needed data`))
                })

使用 Promise.reject

responsePromise = Promise.reject(new Error(`Unsupported method "${request.httpMethod}"`));

版本

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

"typescript": "^2.2.2"
"@types/aws-lambda": "0.0.9",
"@types/core-js": "^0.9.40",
"@types/node": "^7.0.12",

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,
        "alwaysStrict": true,
        "preserveConstEnums": true,
        "sourceMap": true,
        "outDir": "dist",
        "moduleResolution": "Node",
        "declaration": true,
        "lib": [
            "es6"
        ]
    },
    "include": [
        "index.ts",
        "lib/**/*.ts"
    ],
    "exclude": [
        "node_modules",
        "**/*.spec.ts"
    ]
}

我正在使用具有以下配置的 grunt-ts 来运行 ts 任务。

ts: {
            app: {
                tsconfig: {
                    tsconfig: "./tsconfig.json",
                    ignoreSettings: true
                }
            },
...

我尝试了 I get: [ts] 'Promise' only refers to a type, but is being used as a value here 中提到的解决方案但没有运气。

最佳答案

我在 aws-sdk 上遇到了同样的问题,我使用 "target": "es2015" 解决了这个问题。这是我的 tsconfig.json 文件。

{
    "compilerOptions": {
        "outDir": "./dist/",
        "sourceMap": false,
        "noImplicitAny": false,
        "module": "commonjs",
        "target": "es2015"
    },
    "include": [
        "src/**/*"
    ],
    "exclude": [
        "node_modules",
        "**/*.spec.ts"
    ]
}

关于javascript - typescript: error TS2693: 'Promise' 只引用了一个类型,但在这里被用作一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43119163/

相关文章:

javascript - JS 中的appendChild 问题

Javascript:我如何找到某个类并将带有编号 ID 的 SPAN 添加到每个单词?

javascript - 模块 ' ' 导入了意外值 ' '。请添加@NgModule 注解

javascript - 带有递归 promise 的合并排序

javascript - 在 React 中将数据传递给父级

javascript - 在 Javascript 中将输入文本从小写转换为大写,反之亦然

angular - 如何在独立的 Angular 2 组件中包含字体

javascript - 如何自动将 TypeScript 转译为 JavaScript?

javascript - Promise join 向链中添加新的函数调用

node.js - 不知道如何使用 csv-writer 在 API 调用后逐行写入 csv 文件