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

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

    Add below line to file where error is being thrown.This should fix the issue

    declare var Promise: any;
    

    P.S: This is definitely not the optimal solution

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

    Core-js did not work for me as it caused other issues, however, simply installing the latest version of npm i @types/es6-promise --save-dev got rid of the issues. The issues for me stemmed from compiling an sdk that was using rxjs. Here is the error I was getting:

    `node_modules/rxjs/Observable.d.ts(59,60): error TS2693: Promise only refers to a type, but is being used as a value here.`
    
    0 讨论(0)
  • 2020-11-29 19:59

    Please be aware that if you are running the tsc command with a file name ie:

    tsc testfile.ts
    

    then the tsconfig.json compiler configuration file is ignored. The solution is to run either the tsc command on its own, in which case all .ts files in the directory will be compiled, unless you have edited the tsconfig.json to include a set of files.

    see 'using the files property'... https://www.typescriptlang.org/docs/handbook/tsconfig-json.html

    0 讨论(0)
  • 2020-11-29 20:01

    Solved by changing the target in compilerOptions.

    {
    "compilerOptions": {
        "module": "es2015",
        "target": "es2015",
        "lib": [
            "es2016",
            "dom"
        ],
        "moduleResolution": "node",
        "noImplicitAny": false,
        "sourceMap": false,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "outDir": "./public/js/app"
    },
    "exclude": [
        "node_modules",
        "public/js",
        "assets/app/polyfills.ts"
    ],
    "angularCompilerOptions": {
        "skipMetadataEmit": true
    }
    }
    
    0 讨论(0)
提交回复
热议问题