-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Promise static method gives error #14858
Comments
You're targeting ES5. Promises are not part of ES5. They're part of ES6/ES2015. To use Promises, you'll need to adjust your lib option in tsconfig (see http://www.typescriptlang.org/docs/handbook/compiler-options.html). |
I've run into the same issue, even when targeting ES6. Writing an extension for Visual Studio Code and have the same problem described above. Trying to compile this: const p = new Promise<string>((resolve, reject) => { resolve('a string') }); with the following {
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "out",
"lib": [ "es6" ],
"sourceMap": true,
"rootDir": ".",
"types": [ "node" ]
},
"exclude": [
"node_modules",
".vscode-test"
]
} results in the following compiler error:
I've been fighting against this for a couple days now and have no idea at all what to do. It does appear to be some kind of bug in the compiler. TypeScript version: 2.2.1 |
@ellismarkf, if you run |
@mhegazy: here are the
|
I am unable to reproduce this locally, can you share a repro project that demonstrates the issue? |
I had the same issue. Reverting to |
I am targeting ES6 and having this issue. +1 |
@mhegazy — turns out it was a silly VSCode misconfiguration. I had forgotten to add a VSCode compilation task, and wasn't compiling the TypeScript code as part of the For others having a similar issue, make sure you have something like the following:
{
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"showOutput": "silent",
"args": ["run", "compile", "--loglevel", "silent"],
"isBackground": true,
"problemMatcher": "$tsc-watch"
}
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${file}",
"outFiles": [ "${workspaceRoot}/out/src/**/*.js" ],
"sourceMaps": true,
"preLaunchTask": "npm"
} The
"scripts": {
"vscode:prepublish": "tsc -p ./",
"compile": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "node ./node_modules/vscode/bin/test"
}
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "out",
"lib": [ "es2015" ],
"sourceMap": true,
"rootDir": ".",
"types": [ "node" ]
},
"exclude": [
"node_modules",
".vscode-test"
]
} Hope that helps someone! Probably not since it was a bit of a silly oversight on my part >.< @mhegazy - thanks for your help! |
> tslint --fix --type-check --project .
Error at src/Server.ts:102:20: 'Promise' only refers to a type, but is being used as a value here.
Error at src/Server.ts:133:20: 'Promise' only refers to a type, but is being used as a value here.
Error at src/Server.ts:149:20: 'Promise' only refers to a type, but is being used as a value here.
Error at src/Server.ts:165:20: 'Promise' only refers to a type, but is being used as a value here. my tsconfig.json {
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "dist",
"rootDirs": [
"src",
"test"
],
"sourceMap": true,
"declaration": true
},
"exclude": [
"node_modules",
"dist"
]
} My code looks like: function myFunction(): Promise<number>{
return new Promise((resolve,reject)=>{
resolve(3);
})
} |
I have the same issue if I delete my tsconfig.json file (my TS config is in my webpack configuration in the ts-loader options). If I create an empty tsconfig.json, no more errors! TS version 2.2.2 |
Try to add : worked for my project... |
I failed to follow up, I ended up using the "lib" option, but what my intent was that TypeScript knows I specified target "es5" that needs a polyfill for |
TypeScript does not inject polyfills into your code. The assumption is you will include these independently. |
Well TS does something when I add |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
I made it! The problem is that Typescript doesn't add polyfills for you, so you have to add them.
and then
wherever you need promises. This is my tsconfig.json
|
Could someone explain why the code in the following repository doesn't work? I think I've stripped everything down to the most simple version possible and I still get the Promise error. https://github.com/danielcovill/typescript-issue edit: it appears the solution is not to include parameters as they result in tsconfig.json being ignored. If parameters must be supplied, include "--target es6". |
Still having this issue; these little errors are annyoing |
See a solution here: https://stackoverflow.com/a/51334882/984471 |
TypeScript Version: 2.2.1
Steps to Reproduce:
src/main.ts(17,9): error TS2693: 'Promise' only refers to a type, but is being used as a value here.
Comment
I really think the TS compiler should be smart enough to figure out what "basic" types to include based off the field target from the TS configuration files, tsconfig.json
Aside: As a developer, the last thing I care about is wasting my time with stupid typing errors, the entire typing system needs to be hidden from the developer.
package.json dependencies
The text was updated successfully, but these errors were encountered: