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

前端 未结 22 2530
猫巷女王i
猫巷女王i 2020-11-29 19:35

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,          


        
相关标签:
22条回答
  • 2020-11-29 19:48

    npm i --save-dev @types/es6-promise

    after up command, you'd better check tsconfig.json make sure the "target" must great than "es6". maybe tsc not support es5 yet.

    0 讨论(0)
  • 2020-11-29 19:50

    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"
        ]
    }
    
    0 讨论(0)
  • 2020-11-29 19:51

    I got rid of this same error in index.ts with these combined properties:

    In tsconfig.json:

      "compilerOptions": {
        "target": "ES6"
    

    And in package.json:

      "main": "index.ts",
      "scripts": {
        "start": "tsc -p tsconfig.json && node index.js"
    
    0 讨论(0)
  • 2020-11-29 19:56

    Well, this might be counter-intuitive but I solved this adding esnext to my lib.

    {
      "compilerOptions": {
        "lib": [
            "esnext"
        ],
        "target": "es5",
      }
    }
    

    The FIX, as suggested by the compiler is to

    Try changing the lib compiler option to es2015 or later.

    0 讨论(0)
  • 2020-11-29 19:57

    I solved this by adding below code to tsconfig.json file.

    "lib": [
        "ES5",
        "ES2015",
        "DOM",
        "ScriptHost"]
    
    0 讨论(0)
  • 2020-11-29 19:57

    None of the up-voted answers here work for me. Here is a guaranteed and reasonable solution. Put this near the top of any code file that uses Promise...

    declare const Promise: any;
    
    0 讨论(0)
提交回复
热议问题