2
votes

I have an Angular 4 project powered with webpack. I used TypeScript in the project and I'm using WebStorm as an IDE.

In my code, I use Set without problem.

I want to use Set as well in my unit test to return a value from a mocked function.

When I try to use new Set(['A', 'B']), I see an error in WebStorm:

Set only refers to a type but it is being used as a value

This error is coming from TSLint (I assume) but I can't see the same error in Iterm when I run the TSLint class manually (so I assume it is WebStorm that is not recognizing Set).

In WebStorm configuration, TSLint is enable and look at tsconfig.json, this is the compilerOptions part of tsconfig.json:

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "noEmit": true,
    "noEmitHelpers": true,
    "importHelpers": true,
    "strictNullChecks": false,
    "lib": [
      "es6",
      "es2017",
      "dom"
    ],
    "typeRoots": [
      "node_modules/@types"
    ],
    "types": [
      "hammerjs",
      "jasmine",
      "node",
      "source-map",
      "uglify-js",
      "webpack"
    ],
  },
}

Any idea why WebStorm is complaining (only inside unit test)?

1

1 Answers

1
votes

I found a solution, not sure if it's the good one but I installed @types/es6-collections

npm install --save-dev @types/es6-collections

And add it in tsconfig.json:

"types": [
      "es6-collections",
      "hammerjs",
      "jasmine",
      "node",
      "source-map",
      "uglify-js",
      "webpack"
    ],

That removes the error from webstorm for me