Object.entries () and Object.values ​​() are not typed as arrays in WebStorm / PhpStorm

I have a TypeScript project with ES6 target, it uses core-js to polyfill ES2017 functions, and tsconfig.json is configured accordingly.

When Object.entries(...) and Object.values(...) , the results do not have array methods and properties ( map , forEach , length , etc.), they are displayed as simple objects for the IDE, so any[] must be explicitly set:

While Object.keys(...) behaves as it should.

At the same time, the IDE somehow "knows" about the corresponding types for Object.entries and Object.values , they are displayed in accordance with TypeScript lib.es2017.object.d.ts in Ctrl + Shift + P. But, it seems they ignore types to check because overriding the ObjectConstructor in the current file solves the problem:

 interface ObjectConstructor { values(o: any): any[]; entries(o: any): [string, any][]; } 

tsc seems to be great for typing, so it looks like an IDE specific issue.

This only happens if the Use TypeScript service in Languages & Frameworks > TypeScript not installed. Everything works fine when the TypeScript service is turned on (it is turned off intentionally because there were problems with the 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 it mean? Did something happen to me?

The problem persists with TypeScript 2.1.5 and the latest IDE (EAP 2017.1).

+5
source share
2 answers

Typescript 2.3 there is a new support for iterators behind the compiler flag --downlevel-iteration or setting .compilerOptions.downlevelIteration to true in tsconfig.json .

Please note that this answer is the same as which one , since it refers to the same compiler flag and similar symptoms, although one refers to problems with the compiler, and this one is about some IDE integration.

+2
source

go into your tsconfig.json and change target, lib and module to es2017.

0
source

Source: https://habr.com/ru/post/1263690/


All Articles