typescript:error TS2693:'Promise'只引用一个类型,但在这里被用作值 [英] typescript: error TS2693: 'Promise' only refers to a type, but is being used as a value here

查看:2679
本文介绍了typescript:error TS2693:'Promise'只引用一个类型,但在这里被用作值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to use Typescript for my AWS Lambda and i am getting the following errors where ever I use 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

使用Promise构造函数

Using the Promise constructor

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

使用Promise.reject

using Promise.reject

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



版本



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

Versions

Following are the versions in my dev dependencies:

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



tsconfig.json的内容



Contents of 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任务。

I am using grunt-ts with the following configuration for running ts task.

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

我试过我得到:[ts]'Promise'仅指一种类型,但在这里被用作值但没有运气。

推荐答案

我对 aws-sdk 也有同样的问题,我用target解决了这个问题:es2015。这是我的 tsconfig.json 文件。

I had the same issue with the aws-sdk and I solved it by using "target": "es2015". This is my tsconfig.json file.

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

这篇关于typescript:error TS2693:'Promise'只引用一个类型,但在这里被用作值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆