typescript: error TS2693: 'Promise' only refers to a type, but is being used as a value here
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, but is being used as a value here.
I tried using the following variations in the code
Using the Promise constructor
responsePromise = new Promise((resolve, reject) => {
return reject(new Error(`missing is needed data`))
})
using Promise.reject
responsePromise = Promise.reject(new Error(`Unsupported method "${request.httpMethod}"`));
Versions
Following are the versions in my dev dependencies:
"typescript": "^2.2.2"
"@types/aws-lambda": "0.0.9",
"@types/core-js": "^0.9.40",
"@types/node": "^7.0.12",
Contents of tsconfig.json
{
"compileOnSave": true,
"compilerOptions": {
"module": "commonjs",
// "typeRoots" : ["./typings", "./node_modules/@types"],
"target": "es5",
// "types" : [ "core-js" ],
"noImplicitAny": true,
"strictNullChecks": true,
"allowJs": true,
"noEmit": true,
"alwaysStrict": true,
"preserveConstEnums": true,
"sourceMap": true,
"outDir": "dist",
"moduleResolution": "Node",
"declaration": true,
"lib": [
"es6"
]
},
"include": [
"index.ts",
"lib/**/*.ts"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
I am using grunt-ts with the following configuration for running ts task.
ts: {
app: {
tsconfig: {
tsconfig: "./tsconfig.json",
ignoreSettings: true
}
},
...
I tried with the solution mentioned in I get: [ts] 'Promise' only refers to a type, but is being used as a value here but no luck.
javascript typescript promise
|
show 3 more comments
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, but is being used as a value here.
I tried using the following variations in the code
Using the Promise constructor
responsePromise = new Promise((resolve, reject) => {
return reject(new Error(`missing is needed data`))
})
using Promise.reject
responsePromise = Promise.reject(new Error(`Unsupported method "${request.httpMethod}"`));
Versions
Following are the versions in my dev dependencies:
"typescript": "^2.2.2"
"@types/aws-lambda": "0.0.9",
"@types/core-js": "^0.9.40",
"@types/node": "^7.0.12",
Contents of tsconfig.json
{
"compileOnSave": true,
"compilerOptions": {
"module": "commonjs",
// "typeRoots" : ["./typings", "./node_modules/@types"],
"target": "es5",
// "types" : [ "core-js" ],
"noImplicitAny": true,
"strictNullChecks": true,
"allowJs": true,
"noEmit": true,
"alwaysStrict": true,
"preserveConstEnums": true,
"sourceMap": true,
"outDir": "dist",
"moduleResolution": "Node",
"declaration": true,
"lib": [
"es6"
]
},
"include": [
"index.ts",
"lib/**/*.ts"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
I am using grunt-ts with the following configuration for running ts task.
ts: {
app: {
tsconfig: {
tsconfig: "./tsconfig.json",
ignoreSettings: true
}
},
...
I tried with the solution mentioned in I get: [ts] 'Promise' only refers to a type, but is being used as a value here but no luck.
javascript typescript promise
1
No return value is needed for the callback function passed in to the Promise constructor. Just get rid ofreturn
.
– Pointy
Mar 30 '17 at 13:23
Do you mean like this?responsePromise = new Promise((resolve, reject) => { reject(new Error("missing is needed data"))})
I tried it. But it did not hep with the problem.
– kalyanvgopal
Mar 30 '17 at 13:29
Yes. JavaScript doesn't care whether you return a value or not, but it won't pay attention to it. TypeScript, however, does care.
– Pointy
Mar 30 '17 at 13:30
Got it. But why does tsc fails to compile any flavour of Promose.resolve or Promise.reject?
– kalyanvgopal
Mar 30 '17 at 13:33
That, I don't know. How exactly isresponsePromise
declared?
– Pointy
Mar 30 '17 at 13:35
|
show 3 more comments
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, but is being used as a value here.
I tried using the following variations in the code
Using the Promise constructor
responsePromise = new Promise((resolve, reject) => {
return reject(new Error(`missing is needed data`))
})
using Promise.reject
responsePromise = Promise.reject(new Error(`Unsupported method "${request.httpMethod}"`));
Versions
Following are the versions in my dev dependencies:
"typescript": "^2.2.2"
"@types/aws-lambda": "0.0.9",
"@types/core-js": "^0.9.40",
"@types/node": "^7.0.12",
Contents of tsconfig.json
{
"compileOnSave": true,
"compilerOptions": {
"module": "commonjs",
// "typeRoots" : ["./typings", "./node_modules/@types"],
"target": "es5",
// "types" : [ "core-js" ],
"noImplicitAny": true,
"strictNullChecks": true,
"allowJs": true,
"noEmit": true,
"alwaysStrict": true,
"preserveConstEnums": true,
"sourceMap": true,
"outDir": "dist",
"moduleResolution": "Node",
"declaration": true,
"lib": [
"es6"
]
},
"include": [
"index.ts",
"lib/**/*.ts"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
I am using grunt-ts with the following configuration for running ts task.
ts: {
app: {
tsconfig: {
tsconfig: "./tsconfig.json",
ignoreSettings: true
}
},
...
I tried with the solution mentioned in I get: [ts] 'Promise' only refers to a type, but is being used as a value here but no luck.
javascript typescript promise
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, but is being used as a value here.
I tried using the following variations in the code
Using the Promise constructor
responsePromise = new Promise((resolve, reject) => {
return reject(new Error(`missing is needed data`))
})
using Promise.reject
responsePromise = Promise.reject(new Error(`Unsupported method "${request.httpMethod}"`));
Versions
Following are the versions in my dev dependencies:
"typescript": "^2.2.2"
"@types/aws-lambda": "0.0.9",
"@types/core-js": "^0.9.40",
"@types/node": "^7.0.12",
Contents of tsconfig.json
{
"compileOnSave": true,
"compilerOptions": {
"module": "commonjs",
// "typeRoots" : ["./typings", "./node_modules/@types"],
"target": "es5",
// "types" : [ "core-js" ],
"noImplicitAny": true,
"strictNullChecks": true,
"allowJs": true,
"noEmit": true,
"alwaysStrict": true,
"preserveConstEnums": true,
"sourceMap": true,
"outDir": "dist",
"moduleResolution": "Node",
"declaration": true,
"lib": [
"es6"
]
},
"include": [
"index.ts",
"lib/**/*.ts"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
I am using grunt-ts with the following configuration for running ts task.
ts: {
app: {
tsconfig: {
tsconfig: "./tsconfig.json",
ignoreSettings: true
}
},
...
I tried with the solution mentioned in I get: [ts] 'Promise' only refers to a type, but is being used as a value here but no luck.
javascript typescript promise
javascript typescript promise
edited Jul 24 '18 at 18:32
Community♦
11
11
asked Mar 30 '17 at 13:22
kalyanvgopalkalyanvgopal
7162712
7162712
1
No return value is needed for the callback function passed in to the Promise constructor. Just get rid ofreturn
.
– Pointy
Mar 30 '17 at 13:23
Do you mean like this?responsePromise = new Promise((resolve, reject) => { reject(new Error("missing is needed data"))})
I tried it. But it did not hep with the problem.
– kalyanvgopal
Mar 30 '17 at 13:29
Yes. JavaScript doesn't care whether you return a value or not, but it won't pay attention to it. TypeScript, however, does care.
– Pointy
Mar 30 '17 at 13:30
Got it. But why does tsc fails to compile any flavour of Promose.resolve or Promise.reject?
– kalyanvgopal
Mar 30 '17 at 13:33
That, I don't know. How exactly isresponsePromise
declared?
– Pointy
Mar 30 '17 at 13:35
|
show 3 more comments
1
No return value is needed for the callback function passed in to the Promise constructor. Just get rid ofreturn
.
– Pointy
Mar 30 '17 at 13:23
Do you mean like this?responsePromise = new Promise((resolve, reject) => { reject(new Error("missing is needed data"))})
I tried it. But it did not hep with the problem.
– kalyanvgopal
Mar 30 '17 at 13:29
Yes. JavaScript doesn't care whether you return a value or not, but it won't pay attention to it. TypeScript, however, does care.
– Pointy
Mar 30 '17 at 13:30
Got it. But why does tsc fails to compile any flavour of Promose.resolve or Promise.reject?
– kalyanvgopal
Mar 30 '17 at 13:33
That, I don't know. How exactly isresponsePromise
declared?
– Pointy
Mar 30 '17 at 13:35
1
1
No return value is needed for the callback function passed in to the Promise constructor. Just get rid of
return
.– Pointy
Mar 30 '17 at 13:23
No return value is needed for the callback function passed in to the Promise constructor. Just get rid of
return
.– Pointy
Mar 30 '17 at 13:23
Do you mean like this?
responsePromise = new Promise((resolve, reject) => { reject(new Error("missing is needed data"))})
I tried it. But it did not hep with the problem.– kalyanvgopal
Mar 30 '17 at 13:29
Do you mean like this?
responsePromise = new Promise((resolve, reject) => { reject(new Error("missing is needed data"))})
I tried it. But it did not hep with the problem.– kalyanvgopal
Mar 30 '17 at 13:29
Yes. JavaScript doesn't care whether you return a value or not, but it won't pay attention to it. TypeScript, however, does care.
– Pointy
Mar 30 '17 at 13:30
Yes. JavaScript doesn't care whether you return a value or not, but it won't pay attention to it. TypeScript, however, does care.
– Pointy
Mar 30 '17 at 13:30
Got it. But why does tsc fails to compile any flavour of Promose.resolve or Promise.reject?
– kalyanvgopal
Mar 30 '17 at 13:33
Got it. But why does tsc fails to compile any flavour of Promose.resolve or Promise.reject?
– kalyanvgopal
Mar 30 '17 at 13:33
That, I don't know. How exactly is
responsePromise
declared?– Pointy
Mar 30 '17 at 13:35
That, I don't know. How exactly is
responsePromise
declared?– Pointy
Mar 30 '17 at 13:35
|
show 3 more comments
19 Answers
19
active
oldest
votes
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"
]
}
2
Thanks Sandro. Tried same but did not help in my case.
– kalyanvgopal
Mar 30 '17 at 16:22
Maybe the@types/aws-lambda
are out of date. Amazon ships Typescript types with the official SDK. There is no need for DefinitelyTyped.
– Sandro Keil
Mar 31 '17 at 8:54
That solved the exact error defined in the question for me and I was just importing rxjs, not even using Promis. Thanks so much!
– muzurBurcu
May 26 '17 at 2:22
2
This is probably the best answer for those who were targeting es5 to begin with. Switching from es5 to es2015 also fixed this for me as well. Be warned however, you likely will still see the error until you shut down and restart your IDE/editor. Something about the TSC (or it's watch mode) was making it appear that this wasn't fixing it when it really was, but required a restart of vscode.
– user2080225
Oct 9 '17 at 23:30
7
update/addendum: if you want to still target es5 (for better browser support, and is important) that does still work as long as you supply this in your compiler options: "lib" : ["es2015", "dom", "ScriptHost"], The trick for me was realizing i had to restart VSCode editor, before it would begin working after making that change.
– user2080225
Oct 10 '17 at 1:39
add a comment |
Encounter the same error today and solved it with:
npm i --save-dev @types/es6-promise
Update:
add:
import {Promise} from 'es6-promise'
2
+ and restarting VS Code helps too, after installation of the types
– Legends
Feb 6 '18 at 23:31
Tried it, not working
– Loic Coenen
Apr 2 '18 at 13:49
3
Erratum: It works using this lineimport {Promise} from 'es6-promise'
;
– Loic Coenen
Apr 2 '18 at 13:52
where to add "import {Promise} from 'es6-promise'" ?
– bArraxas
Jul 24 '18 at 7:54
add a comment |
I solved this by adding below code to tsconfig.json file.
"lib": [
"ES5",
"ES2015",
"DOM",
"ScriptHost"]
2
this worked for me, but note that the "lib" array needs to be inside of the "compilerOptions" object in the tsconfig.json file.
– BillyRayCyrus
Jun 29 '17 at 14:46
2
Using TypeScript 2.4.1 I had to change all of the characters in the string array to be lowercase. Then it worked. Many thanks.
– JDTLH9
Jul 18 '17 at 10:57
add a comment |
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
}
}
add a comment |
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 )
3
This is listed in multiple of the answers here and it important for sure: "Restart IDE (this action is required)"
– atconway
Sep 19 '18 at 19:07
add a comment |
Add below line to file where error is being thrown.This should fix the issue
declare var Promise: any;
14
This is just removing the type check for 'Promise,' rather than fixing it so Typescript finds the correct type.
– edibleEnergy
Dec 11 '17 at 1:05
1
This workaround does not work with Internet Explorer 11 for example. I throws an 'undefined' error when trying to use Promise. Anyway with Chrome the workaround does his job.
– adSad
Jun 21 '18 at 7:59
add a comment |
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"
}
},
...
add a comment |
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;
add a comment |
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/**/*
]
}
3
Yes tartgeting es6 should fix it, but then you have less browser compatibility. Most apps are still today targeting es5, because many browsers still aren't on es6 yet (as of 2017)
– user2080225
Oct 9 '17 at 22:59
@user2080225 although that is true, it doesn't make my answer less correct since the original question didn't state anything about browser compatibility. Therefore this solution could still help others like it helped me.
– Fanus du Toit
Apr 9 '18 at 19:26
add a comment |
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';
add a comment |
I am using the "promise-polyfill"
library, which may be the cause of my issue.
I added this import to the top of my file:
import {Promise} from 'es6-promise';
add a comment |
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"]
}
add a comment |
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
add a comment |
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.`
add a comment |
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"
]
}
add a comment |
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.
add a comment |
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.
add a comment |
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.
add a comment |
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.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f43119163%2ftypescript-error-ts2693-promise-only-refers-to-a-type-but-is-being-used-as%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
19 Answers
19
active
oldest
votes
19 Answers
19
active
oldest
votes
active
oldest
votes
active
oldest
votes
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"
]
}
2
Thanks Sandro. Tried same but did not help in my case.
– kalyanvgopal
Mar 30 '17 at 16:22
Maybe the@types/aws-lambda
are out of date. Amazon ships Typescript types with the official SDK. There is no need for DefinitelyTyped.
– Sandro Keil
Mar 31 '17 at 8:54
That solved the exact error defined in the question for me and I was just importing rxjs, not even using Promis. Thanks so much!
– muzurBurcu
May 26 '17 at 2:22
2
This is probably the best answer for those who were targeting es5 to begin with. Switching from es5 to es2015 also fixed this for me as well. Be warned however, you likely will still see the error until you shut down and restart your IDE/editor. Something about the TSC (or it's watch mode) was making it appear that this wasn't fixing it when it really was, but required a restart of vscode.
– user2080225
Oct 9 '17 at 23:30
7
update/addendum: if you want to still target es5 (for better browser support, and is important) that does still work as long as you supply this in your compiler options: "lib" : ["es2015", "dom", "ScriptHost"], The trick for me was realizing i had to restart VSCode editor, before it would begin working after making that change.
– user2080225
Oct 10 '17 at 1:39
add a comment |
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"
]
}
2
Thanks Sandro. Tried same but did not help in my case.
– kalyanvgopal
Mar 30 '17 at 16:22
Maybe the@types/aws-lambda
are out of date. Amazon ships Typescript types with the official SDK. There is no need for DefinitelyTyped.
– Sandro Keil
Mar 31 '17 at 8:54
That solved the exact error defined in the question for me and I was just importing rxjs, not even using Promis. Thanks so much!
– muzurBurcu
May 26 '17 at 2:22
2
This is probably the best answer for those who were targeting es5 to begin with. Switching from es5 to es2015 also fixed this for me as well. Be warned however, you likely will still see the error until you shut down and restart your IDE/editor. Something about the TSC (or it's watch mode) was making it appear that this wasn't fixing it when it really was, but required a restart of vscode.
– user2080225
Oct 9 '17 at 23:30
7
update/addendum: if you want to still target es5 (for better browser support, and is important) that does still work as long as you supply this in your compiler options: "lib" : ["es2015", "dom", "ScriptHost"], The trick for me was realizing i had to restart VSCode editor, before it would begin working after making that change.
– user2080225
Oct 10 '17 at 1:39
add a comment |
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 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"
]
}
answered Mar 30 '17 at 15:41
Sandro KeilSandro Keil
1,067164
1,067164
2
Thanks Sandro. Tried same but did not help in my case.
– kalyanvgopal
Mar 30 '17 at 16:22
Maybe the@types/aws-lambda
are out of date. Amazon ships Typescript types with the official SDK. There is no need for DefinitelyTyped.
– Sandro Keil
Mar 31 '17 at 8:54
That solved the exact error defined in the question for me and I was just importing rxjs, not even using Promis. Thanks so much!
– muzurBurcu
May 26 '17 at 2:22
2
This is probably the best answer for those who were targeting es5 to begin with. Switching from es5 to es2015 also fixed this for me as well. Be warned however, you likely will still see the error until you shut down and restart your IDE/editor. Something about the TSC (or it's watch mode) was making it appear that this wasn't fixing it when it really was, but required a restart of vscode.
– user2080225
Oct 9 '17 at 23:30
7
update/addendum: if you want to still target es5 (for better browser support, and is important) that does still work as long as you supply this in your compiler options: "lib" : ["es2015", "dom", "ScriptHost"], The trick for me was realizing i had to restart VSCode editor, before it would begin working after making that change.
– user2080225
Oct 10 '17 at 1:39
add a comment |
2
Thanks Sandro. Tried same but did not help in my case.
– kalyanvgopal
Mar 30 '17 at 16:22
Maybe the@types/aws-lambda
are out of date. Amazon ships Typescript types with the official SDK. There is no need for DefinitelyTyped.
– Sandro Keil
Mar 31 '17 at 8:54
That solved the exact error defined in the question for me and I was just importing rxjs, not even using Promis. Thanks so much!
– muzurBurcu
May 26 '17 at 2:22
2
This is probably the best answer for those who were targeting es5 to begin with. Switching from es5 to es2015 also fixed this for me as well. Be warned however, you likely will still see the error until you shut down and restart your IDE/editor. Something about the TSC (or it's watch mode) was making it appear that this wasn't fixing it when it really was, but required a restart of vscode.
– user2080225
Oct 9 '17 at 23:30
7
update/addendum: if you want to still target es5 (for better browser support, and is important) that does still work as long as you supply this in your compiler options: "lib" : ["es2015", "dom", "ScriptHost"], The trick for me was realizing i had to restart VSCode editor, before it would begin working after making that change.
– user2080225
Oct 10 '17 at 1:39
2
2
Thanks Sandro. Tried same but did not help in my case.
– kalyanvgopal
Mar 30 '17 at 16:22
Thanks Sandro. Tried same but did not help in my case.
– kalyanvgopal
Mar 30 '17 at 16:22
Maybe the
@types/aws-lambda
are out of date. Amazon ships Typescript types with the official SDK. There is no need for DefinitelyTyped.– Sandro Keil
Mar 31 '17 at 8:54
Maybe the
@types/aws-lambda
are out of date. Amazon ships Typescript types with the official SDK. There is no need for DefinitelyTyped.– Sandro Keil
Mar 31 '17 at 8:54
That solved the exact error defined in the question for me and I was just importing rxjs, not even using Promis. Thanks so much!
– muzurBurcu
May 26 '17 at 2:22
That solved the exact error defined in the question for me and I was just importing rxjs, not even using Promis. Thanks so much!
– muzurBurcu
May 26 '17 at 2:22
2
2
This is probably the best answer for those who were targeting es5 to begin with. Switching from es5 to es2015 also fixed this for me as well. Be warned however, you likely will still see the error until you shut down and restart your IDE/editor. Something about the TSC (or it's watch mode) was making it appear that this wasn't fixing it when it really was, but required a restart of vscode.
– user2080225
Oct 9 '17 at 23:30
This is probably the best answer for those who were targeting es5 to begin with. Switching from es5 to es2015 also fixed this for me as well. Be warned however, you likely will still see the error until you shut down and restart your IDE/editor. Something about the TSC (or it's watch mode) was making it appear that this wasn't fixing it when it really was, but required a restart of vscode.
– user2080225
Oct 9 '17 at 23:30
7
7
update/addendum: if you want to still target es5 (for better browser support, and is important) that does still work as long as you supply this in your compiler options: "lib" : ["es2015", "dom", "ScriptHost"], The trick for me was realizing i had to restart VSCode editor, before it would begin working after making that change.
– user2080225
Oct 10 '17 at 1:39
update/addendum: if you want to still target es5 (for better browser support, and is important) that does still work as long as you supply this in your compiler options: "lib" : ["es2015", "dom", "ScriptHost"], The trick for me was realizing i had to restart VSCode editor, before it would begin working after making that change.
– user2080225
Oct 10 '17 at 1:39
add a comment |
Encounter the same error today and solved it with:
npm i --save-dev @types/es6-promise
Update:
add:
import {Promise} from 'es6-promise'
2
+ and restarting VS Code helps too, after installation of the types
– Legends
Feb 6 '18 at 23:31
Tried it, not working
– Loic Coenen
Apr 2 '18 at 13:49
3
Erratum: It works using this lineimport {Promise} from 'es6-promise'
;
– Loic Coenen
Apr 2 '18 at 13:52
where to add "import {Promise} from 'es6-promise'" ?
– bArraxas
Jul 24 '18 at 7:54
add a comment |
Encounter the same error today and solved it with:
npm i --save-dev @types/es6-promise
Update:
add:
import {Promise} from 'es6-promise'
2
+ and restarting VS Code helps too, after installation of the types
– Legends
Feb 6 '18 at 23:31
Tried it, not working
– Loic Coenen
Apr 2 '18 at 13:49
3
Erratum: It works using this lineimport {Promise} from 'es6-promise'
;
– Loic Coenen
Apr 2 '18 at 13:52
where to add "import {Promise} from 'es6-promise'" ?
– bArraxas
Jul 24 '18 at 7:54
add a comment |
Encounter the same error today and solved it with:
npm i --save-dev @types/es6-promise
Update:
add:
import {Promise} from 'es6-promise'
Encounter the same error today and solved it with:
npm i --save-dev @types/es6-promise
Update:
add:
import {Promise} from 'es6-promise'
edited Jun 21 '18 at 11:09
TlmaK0
1,86711738
1,86711738
answered Sep 10 '17 at 0:45
KenshinKenshin
82244
82244
2
+ and restarting VS Code helps too, after installation of the types
– Legends
Feb 6 '18 at 23:31
Tried it, not working
– Loic Coenen
Apr 2 '18 at 13:49
3
Erratum: It works using this lineimport {Promise} from 'es6-promise'
;
– Loic Coenen
Apr 2 '18 at 13:52
where to add "import {Promise} from 'es6-promise'" ?
– bArraxas
Jul 24 '18 at 7:54
add a comment |
2
+ and restarting VS Code helps too, after installation of the types
– Legends
Feb 6 '18 at 23:31
Tried it, not working
– Loic Coenen
Apr 2 '18 at 13:49
3
Erratum: It works using this lineimport {Promise} from 'es6-promise'
;
– Loic Coenen
Apr 2 '18 at 13:52
where to add "import {Promise} from 'es6-promise'" ?
– bArraxas
Jul 24 '18 at 7:54
2
2
+ and restarting VS Code helps too, after installation of the types
– Legends
Feb 6 '18 at 23:31
+ and restarting VS Code helps too, after installation of the types
– Legends
Feb 6 '18 at 23:31
Tried it, not working
– Loic Coenen
Apr 2 '18 at 13:49
Tried it, not working
– Loic Coenen
Apr 2 '18 at 13:49
3
3
Erratum: It works using this line
import {Promise} from 'es6-promise'
;– Loic Coenen
Apr 2 '18 at 13:52
Erratum: It works using this line
import {Promise} from 'es6-promise'
;– Loic Coenen
Apr 2 '18 at 13:52
where to add "import {Promise} from 'es6-promise'" ?
– bArraxas
Jul 24 '18 at 7:54
where to add "import {Promise} from 'es6-promise'" ?
– bArraxas
Jul 24 '18 at 7:54
add a comment |
I solved this by adding below code to tsconfig.json file.
"lib": [
"ES5",
"ES2015",
"DOM",
"ScriptHost"]
2
this worked for me, but note that the "lib" array needs to be inside of the "compilerOptions" object in the tsconfig.json file.
– BillyRayCyrus
Jun 29 '17 at 14:46
2
Using TypeScript 2.4.1 I had to change all of the characters in the string array to be lowercase. Then it worked. Many thanks.
– JDTLH9
Jul 18 '17 at 10:57
add a comment |
I solved this by adding below code to tsconfig.json file.
"lib": [
"ES5",
"ES2015",
"DOM",
"ScriptHost"]
2
this worked for me, but note that the "lib" array needs to be inside of the "compilerOptions" object in the tsconfig.json file.
– BillyRayCyrus
Jun 29 '17 at 14:46
2
Using TypeScript 2.4.1 I had to change all of the characters in the string array to be lowercase. Then it worked. Many thanks.
– JDTLH9
Jul 18 '17 at 10:57
add a comment |
I solved this by adding below code to tsconfig.json file.
"lib": [
"ES5",
"ES2015",
"DOM",
"ScriptHost"]
I solved this by adding below code to tsconfig.json file.
"lib": [
"ES5",
"ES2015",
"DOM",
"ScriptHost"]
edited May 18 '17 at 20:54
csano
10.7k12241
10.7k12241
answered May 14 '17 at 8:59
NileshNilesh
29922
29922
2
this worked for me, but note that the "lib" array needs to be inside of the "compilerOptions" object in the tsconfig.json file.
– BillyRayCyrus
Jun 29 '17 at 14:46
2
Using TypeScript 2.4.1 I had to change all of the characters in the string array to be lowercase. Then it worked. Many thanks.
– JDTLH9
Jul 18 '17 at 10:57
add a comment |
2
this worked for me, but note that the "lib" array needs to be inside of the "compilerOptions" object in the tsconfig.json file.
– BillyRayCyrus
Jun 29 '17 at 14:46
2
Using TypeScript 2.4.1 I had to change all of the characters in the string array to be lowercase. Then it worked. Many thanks.
– JDTLH9
Jul 18 '17 at 10:57
2
2
this worked for me, but note that the "lib" array needs to be inside of the "compilerOptions" object in the tsconfig.json file.
– BillyRayCyrus
Jun 29 '17 at 14:46
this worked for me, but note that the "lib" array needs to be inside of the "compilerOptions" object in the tsconfig.json file.
– BillyRayCyrus
Jun 29 '17 at 14:46
2
2
Using TypeScript 2.4.1 I had to change all of the characters in the string array to be lowercase. Then it worked. Many thanks.
– JDTLH9
Jul 18 '17 at 10:57
Using TypeScript 2.4.1 I had to change all of the characters in the string array to be lowercase. Then it worked. Many thanks.
– JDTLH9
Jul 18 '17 at 10:57
add a comment |
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
}
}
add a comment |
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
}
}
add a comment |
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
}
}
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
}
}
answered May 31 '17 at 20:02
Mani SMani S
1,103512
1,103512
add a comment |
add a comment |
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 )
3
This is listed in multiple of the answers here and it important for sure: "Restart IDE (this action is required)"
– atconway
Sep 19 '18 at 19:07
add a comment |
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 )
3
This is listed in multiple of the answers here and it important for sure: "Restart IDE (this action is required)"
– atconway
Sep 19 '18 at 19:07
add a comment |
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 )
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 )
edited May 9 '18 at 11:07
answered Mar 25 '18 at 15:10
Nhan CaoNhan Cao
1,430910
1,430910
3
This is listed in multiple of the answers here and it important for sure: "Restart IDE (this action is required)"
– atconway
Sep 19 '18 at 19:07
add a comment |
3
This is listed in multiple of the answers here and it important for sure: "Restart IDE (this action is required)"
– atconway
Sep 19 '18 at 19:07
3
3
This is listed in multiple of the answers here and it important for sure: "Restart IDE (this action is required)"
– atconway
Sep 19 '18 at 19:07
This is listed in multiple of the answers here and it important for sure: "Restart IDE (this action is required)"
– atconway
Sep 19 '18 at 19:07
add a comment |
Add below line to file where error is being thrown.This should fix the issue
declare var Promise: any;
14
This is just removing the type check for 'Promise,' rather than fixing it so Typescript finds the correct type.
– edibleEnergy
Dec 11 '17 at 1:05
1
This workaround does not work with Internet Explorer 11 for example. I throws an 'undefined' error when trying to use Promise. Anyway with Chrome the workaround does his job.
– adSad
Jun 21 '18 at 7:59
add a comment |
Add below line to file where error is being thrown.This should fix the issue
declare var Promise: any;
14
This is just removing the type check for 'Promise,' rather than fixing it so Typescript finds the correct type.
– edibleEnergy
Dec 11 '17 at 1:05
1
This workaround does not work with Internet Explorer 11 for example. I throws an 'undefined' error when trying to use Promise. Anyway with Chrome the workaround does his job.
– adSad
Jun 21 '18 at 7:59
add a comment |
Add below line to file where error is being thrown.This should fix the issue
declare var Promise: any;
Add below line to file where error is being thrown.This should fix the issue
declare var Promise: any;
answered Jun 9 '17 at 9:11
Imamudin NaseemImamudin Naseem
976916
976916
14
This is just removing the type check for 'Promise,' rather than fixing it so Typescript finds the correct type.
– edibleEnergy
Dec 11 '17 at 1:05
1
This workaround does not work with Internet Explorer 11 for example. I throws an 'undefined' error when trying to use Promise. Anyway with Chrome the workaround does his job.
– adSad
Jun 21 '18 at 7:59
add a comment |
14
This is just removing the type check for 'Promise,' rather than fixing it so Typescript finds the correct type.
– edibleEnergy
Dec 11 '17 at 1:05
1
This workaround does not work with Internet Explorer 11 for example. I throws an 'undefined' error when trying to use Promise. Anyway with Chrome the workaround does his job.
– adSad
Jun 21 '18 at 7:59
14
14
This is just removing the type check for 'Promise,' rather than fixing it so Typescript finds the correct type.
– edibleEnergy
Dec 11 '17 at 1:05
This is just removing the type check for 'Promise,' rather than fixing it so Typescript finds the correct type.
– edibleEnergy
Dec 11 '17 at 1:05
1
1
This workaround does not work with Internet Explorer 11 for example. I throws an 'undefined' error when trying to use Promise. Anyway with Chrome the workaround does his job.
– adSad
Jun 21 '18 at 7:59
This workaround does not work with Internet Explorer 11 for example. I throws an 'undefined' error when trying to use Promise. Anyway with Chrome the workaround does his job.
– adSad
Jun 21 '18 at 7:59
add a comment |
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"
}
},
...
add a comment |
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"
}
},
...
add a comment |
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"
}
},
...
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"
}
},
...
edited May 23 '17 at 12:10
Community♦
11
11
answered Apr 3 '17 at 18:41
kalyanvgopalkalyanvgopal
7162712
7162712
add a comment |
add a comment |
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;
add a comment |
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;
add a comment |
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;
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;
answered Apr 6 '18 at 16:56
user1618323user1618323
23246
23246
add a comment |
add a comment |
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/**/*
]
}
3
Yes tartgeting es6 should fix it, but then you have less browser compatibility. Most apps are still today targeting es5, because many browsers still aren't on es6 yet (as of 2017)
– user2080225
Oct 9 '17 at 22:59
@user2080225 although that is true, it doesn't make my answer less correct since the original question didn't state anything about browser compatibility. Therefore this solution could still help others like it helped me.
– Fanus du Toit
Apr 9 '18 at 19:26
add a comment |
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/**/*
]
}
3
Yes tartgeting es6 should fix it, but then you have less browser compatibility. Most apps are still today targeting es5, because many browsers still aren't on es6 yet (as of 2017)
– user2080225
Oct 9 '17 at 22:59
@user2080225 although that is true, it doesn't make my answer less correct since the original question didn't state anything about browser compatibility. Therefore this solution could still help others like it helped me.
– Fanus du Toit
Apr 9 '18 at 19:26
add a comment |
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/**/*
]
}
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/**/*
]
}
answered Aug 11 '17 at 9:35
Fanus du ToitFanus du Toit
436513
436513
3
Yes tartgeting es6 should fix it, but then you have less browser compatibility. Most apps are still today targeting es5, because many browsers still aren't on es6 yet (as of 2017)
– user2080225
Oct 9 '17 at 22:59
@user2080225 although that is true, it doesn't make my answer less correct since the original question didn't state anything about browser compatibility. Therefore this solution could still help others like it helped me.
– Fanus du Toit
Apr 9 '18 at 19:26
add a comment |
3
Yes tartgeting es6 should fix it, but then you have less browser compatibility. Most apps are still today targeting es5, because many browsers still aren't on es6 yet (as of 2017)
– user2080225
Oct 9 '17 at 22:59
@user2080225 although that is true, it doesn't make my answer less correct since the original question didn't state anything about browser compatibility. Therefore this solution could still help others like it helped me.
– Fanus du Toit
Apr 9 '18 at 19:26
3
3
Yes tartgeting es6 should fix it, but then you have less browser compatibility. Most apps are still today targeting es5, because many browsers still aren't on es6 yet (as of 2017)
– user2080225
Oct 9 '17 at 22:59
Yes tartgeting es6 should fix it, but then you have less browser compatibility. Most apps are still today targeting es5, because many browsers still aren't on es6 yet (as of 2017)
– user2080225
Oct 9 '17 at 22:59
@user2080225 although that is true, it doesn't make my answer less correct since the original question didn't state anything about browser compatibility. Therefore this solution could still help others like it helped me.
– Fanus du Toit
Apr 9 '18 at 19:26
@user2080225 although that is true, it doesn't make my answer less correct since the original question didn't state anything about browser compatibility. Therefore this solution could still help others like it helped me.
– Fanus du Toit
Apr 9 '18 at 19:26
add a comment |
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';
add a comment |
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';
add a comment |
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';
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';
edited Aug 8 '17 at 14:13
answered Aug 7 '17 at 9:21
Zack ZilicZack Zilic
378217
378217
add a comment |
add a comment |
I am using the "promise-polyfill"
library, which may be the cause of my issue.
I added this import to the top of my file:
import {Promise} from 'es6-promise';
add a comment |
I am using the "promise-polyfill"
library, which may be the cause of my issue.
I added this import to the top of my file:
import {Promise} from 'es6-promise';
add a comment |
I am using the "promise-polyfill"
library, which may be the cause of my issue.
I added this import to the top of my file:
import {Promise} from 'es6-promise';
I am using the "promise-polyfill"
library, which may be the cause of my issue.
I added this import to the top of my file:
import {Promise} from 'es6-promise';
answered Mar 30 '18 at 23:37
Matthias DaileyMatthias Dailey
4,15742337
4,15742337
add a comment |
add a comment |
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"]
}
add a comment |
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"]
}
add a comment |
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"]
}
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"]
}
edited Aug 18 '18 at 16:39
answered Aug 18 '18 at 16:15
Jon GearJon Gear
566515
566515
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Sep 20 '18 at 12:45
Hazem HASANHazem HASAN
4842720
4842720
add a comment |
add a comment |
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.`
add a comment |
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.`
add a comment |
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.`
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.`
answered Nov 14 '17 at 17:56
Danny FenstermakerDanny Fenstermaker
576510
576510
add a comment |
add a comment |
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"
]
}
add a comment |
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"
]
}
add a comment |
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"
]
}
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"
]
}
answered Feb 8 '18 at 4:47
Camilo SotoCamilo Soto
11610
11610
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Mar 4 '18 at 15:54
MostoneMostone
91
91
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Apr 8 '18 at 15:42
ravish.hackerravish.hacker
618917
618917
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
edited Oct 18 '18 at 14:56
answered Apr 21 '17 at 15:05
DarksealDarkseal
5,51514070
5,51514070
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Dec 29 '18 at 8:43
Salathiel GenèseSalathiel Genèse
787616
787616
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f43119163%2ftypescript-error-ts2693-promise-only-refers-to-a-type-but-is-being-used-as%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
No return value is needed for the callback function passed in to the Promise constructor. Just get rid of
return
.– Pointy
Mar 30 '17 at 13:23
Do you mean like this?
responsePromise = new Promise((resolve, reject) => { reject(new Error("missing is needed data"))})
I tried it. But it did not hep with the problem.– kalyanvgopal
Mar 30 '17 at 13:29
Yes. JavaScript doesn't care whether you return a value or not, but it won't pay attention to it. TypeScript, however, does care.
– Pointy
Mar 30 '17 at 13:30
Got it. But why does tsc fails to compile any flavour of Promose.resolve or Promise.reject?
– kalyanvgopal
Mar 30 '17 at 13:33
That, I don't know. How exactly is
responsePromise
declared?– Pointy
Mar 30 '17 at 13:35