gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 02:37:48 31 4
gpt4 key购买 nike

我正在尝试将 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/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com