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,
Here is my tip. Tested with vscode 1.21.1 (on MAC)
Put below config to tsconfig.json
"lib": [
"es2016",
"dom"
]
into compilerOptions
Restart IDE (this action is required :D )
I had the same issue until I added the following lib array in typeScript 3.0.1
tsconfig.json
{
"compilerOptions": {
"outDir": "lib",
"module": "commonjs",
"allowJs": false,
"declaration": true,
"target": "es5",
"lib": ["dom", "es2015", "es5", "es6"],
"rootDir": "src"
},
"include": ["./**/*"],
"exclude": ["node_modules", "**/*.spec.ts"]
}
If you're using the DefinitelyTyped repository in your project you might be experiencing this recent issue.
A decent workaround you might use (other than waiting for an updated build of the definitions file or refactoring your TS code) is to specify an explicit version+build for the core-js typings rather than let Visual Studio pick the latest/most recent one. I found one that seems to be unaffected by this problem (in my case at least), you can use it replacing the following line from your package.json file:
"scripts": {
"postinstall": "typings install dt~core-js --global"
}
With the following one:
"scripts": {
"postinstall": "typings install dt~core-js@0.9.7+20161130133742 --global"
}
This fixed my issue for good. However, is highly recommended to remove the explicit version+build reference as soon as the issue will be released.
For further info regarding this issue, you can also read this blog post that I wrote on the topic.
Had the same issue with typescript and the aws-sdk
. The solve was to change the target to es6
.
My complete tsconfig.json
file:
{
compilerOptions: {
outDir: ./dist/,
sourceMap: true,
noImplicitAny: true,
module: commonjs,
target: es6,
jsx: react,
allowJs: true
},
include: [
./src/**/*
]
}
I had the same problem and this saved me from the problem in second:
write in console this:
npm i --save bluebird
npm i --save-dev @types/bluebird @types/core-js@0.9.36
in the file where the problem is copy paste this:
import * as Promise from 'bluebird';
Just change the target to "ES2017" in tsconfig.json file.
this is my tsconfig.json file
{
"compilerOptions": {
/* Basic Options */
"target": "ES2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
"outDir": "./dist", /* Redirect output structure to the directory. */
"strict": true /* Enable all strict type-checking options. */
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules"
]
}