I have TypeScript project with ES6 target, it uses core-js
to polyfill ES2017 features and tsconfig.json is configured accordingly.
When Object.entries(...)
and Object.values(...)
are used, the results don't have array methods and properties (map
, forEach
, length
, etc), they appear as plain objects to IDE, so any[]
type should be casted explicitly:
While Object.keys(...)
behaves like it should.
At the same time IDE somehow 'knows' about the proper types for Object.entries
and Object.values
, they are shown in accordance with TypeScript's lib.es2017.object.d.ts
on Ctrl+Shift+P. But it seems to ignore the types for inspection, because overriding ObjectConstructor
in current file solves the problem:
interface ObjectConstructor {
values(o: any): any[];
entries(o: any): [string, any][];
}
tsc
seems to be fine with the typings, so it looks like IDE-specific problem.
This happens only when Use TypeScript service
in Languages & Frameworks > TypeScript
is unchecked. Everything wents normal when TypeScript service is enabled (it is disabled intentionally because there were problems with TS service before).
Here is tsconfig.json:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"alwaysStrict": true,
"strictNullChecks": false,
"baseUrl": "./src",
"paths": [],
"lib": [
"es2016",
"es2017.object"
]
},
"exclude": [
"node_modules"
]
}
What does this mean? Did my setup go wrong somewhere?
The problem persists with TypeScript 2.1.5 and latest IDE (EAP 2017.1).
Typescript 2.3 introduced new support for iterators behind the --downlevel-iteration
compiler flag, or by setting .compilerOptions.downlevelIteration
to true
in your tsconfig.json
.
Note that this answer is the same as that one since it refers to the same compiler flag and similar symptoms, even though one refers to problems with a compiler and this one is about some IDE integration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With