TypeScript: Promise static method gives error
TypeScript Version: 2.2.1
Steps to Reproduce:
- Code used
let p = Promise.resolve([1, 2, 3]);
p.then(function (v) {
console.log(v[0]); // 1
});
- Both the compiler and vscode give this error.
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
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
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
"devDependencies": {
"@types/node": "^7.0.8",
"ava": "^0.18.2",
"browserify": "^14.1.0",
"core-js": "^2.4.1",
"cross-env": "^3.2.4",
"cross-var": "^1.0.3",
"gazeall": "^0.2.5",
"husky": "^0.13.2",
"lite-server": "^2.3.0",
"npm-run-all": "^4.0.2",
"nyc": "^10.1.2",
"shx": "^0.2.2",
"tachyons": "^4.6.2",
"tap-summary": "^3.0.1",
"tape-run": "^3.0.0",
"tslint": "^4.5.1",
"typedoc": "^0.5.7",
"typescript": "^2.2.1",
"typescript-formatter": "^5.1.2"
},
"dependencies": {
"bunyan": "^1.8.8"
},
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 15
- Comments: 20 (5 by maintainers)
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).
@mhegazy yep
ps: little joke, don’t take it hard
my tsconfig.json
My code looks like:
Still having this issue; these little errors are annyoing
Try to add :
"lib": [ "es6", "dom" ]to compilerOptions, then close the file and open again, just for refresh …worked for my project…
I had the same issue. Reverting to
2.2.0solved it for me.