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

前端 未结 22 2527
猫巷女王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:36

    I had this error but I resolved it by using this command, my ts file name is promises-fs.ts:

    tsc promises-fs.ts --target es6 && node promises-fs.js
    

    and the error is gone

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

    I had the same error and I fixed it with this configuration:

    File: tsconfig.json

    {
      "compilerOptions": {
        "target": "es2015",                      
        "module": "commonjs",                    
        "strict": true,                          
        "esModuleInterop": true                  
      }
    }
    
    0 讨论(0)
  • 2020-11-29 19:37

    Having spent lot of time trying to fix this. I had no luck with any solution provide here or elsewhere.

    But then later realised it wasn't so much as just solving the issue. But you also need to RESTART the VSCODE for it to take affect.

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

    The same error here. I fixed this, using "module": "ES6" in tsconfig.

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

    Encounter the same error today and solved it with:

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

    Update:

    add:

    import {Promise} from 'es6-promise'
    
    0 讨论(0)
  • 2020-11-29 19:39

    Finally tsc started working without any errors. But multiple changes. Thanks to Sandro Keil, Pointy & unional

    • Removed dt~aws-lambda
    • Removed options like noEmit,declaration
    • Modified Gruntfile and removed ignoreSettings

    tsconfig.json

    {
        "compileOnSave": true,
        "compilerOptions": {
            "module": "commonjs",
            "target": "es5",
            "noImplicitAny": false,
            "strictNullChecks": true,
            "alwaysStrict": true,
            "preserveConstEnums": true,
            "sourceMap": false,
            "moduleResolution": "Node",
            "lib": [
                "dom",
                "es2015",
                "es5",
                "es6"
            ]
        },
        "include": [
            "*",
            "src/**/*"
        ],
        "exclude": [
            "./node_modules"
        ]
    }
    

    Gruntfile.js

    ts: {
                app: {
                    tsconfig: {
                        tsconfig: "./tsconfig.json"
                    }
                },
    ...
    
    0 讨论(0)
提交回复
热议问题