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,
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.
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"
]
}
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"
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.
I solved this by adding below code to tsconfig.json file.
"lib": [
"ES5",
"ES2015",
"DOM",
"ScriptHost"]
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;