首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >typescript: error TS2693: 'Promise' only refers to a type, but is being used as a value here

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

Stack Overflow用户
提问于 2018-05-14 03:00:44
回答 2查看 0关注 0票数 0

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

代码语言:javascript
复制
error TS2693: 'Promise' only refers to a type, but is being used as a value here.

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

使用Promise构造函数

代码语言:javascript
复制
responsePromise = new Promise((resolve, reject) => {
                    return reject(new Error(`missing is needed data`))
                })

使用Promise.reject

代码语言:javascript
复制
responsePromise = Promise.reject(new Error(`Unsupported method "${request.httpMethod}"`));

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

代码语言:javascript
复制
"typescript": "^2.2.2"
"@types/aws-lambda": "0.0.9",
"@types/core-js": "^0.9.40",
"@types/node": "^7.0.12",

tsconfig.json

代码语言:javascript
复制
{
    "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任务。

代码语言:javascript
复制
ts: {
            app: {
                tsconfig: {
                    tsconfig: "./tsconfig.json",
                    ignoreSettings: true
                }
            },
...
EN

回答 2

Stack Overflow用户

发布于 2018-05-14 11:31:26

代码语言:txt
复制
{
    "compilerOptions": {
        "outDir": "./dist/",
        "sourceMap": false,
        "noImplicitAny": false,
        "module": "commonjs",
        "target": "es2015"
    },
    "include": [
        "src/**/*"
    ],
    "exclude": [
        "node_modules",
        "**/*.spec.ts"
    ]
}
票数 0
EN

Stack Overflow用户

发布于 2018-05-14 12:10:21

代码语言:txt
复制
npm i --save-dev  @types/es6-promise
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100008460

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档