0

I get a compiler error when I run npm test after I make a Map with the factory function that consumes the 'collection' argument (see https://immutable-js.github.io/immutable-js/docs/#/Map/Map). There is no problem when I use the factory function that consumes the 'obj' argument. Why does this variant not work? For my purpose I need to add my own type to the Map, which does not work as well with the 'obj' notation, but seems to work fine with the 'collection' notation.

Strangely enough, this does not happen when I run npm start or when I run the test through Intellij, instead of the command line.

  fit('Immutables test', () => {
//collection notation
    const map = Map([
      ['key', 'value']
    ]);
//obj notation
    const map2 = Map({ 'key': 'value', 'key2': 'value2' });

  });

The result of above test code is a failed unit test:

ERROR in .../my.spec.ts:162:21 - error TS2345: Argument of type 'string[][]' is not assignable to parameter of type '{ [key: string]: {}; }'.
  Index signature is missing in type 'string[][]'.

162     const map = Map([
                        ~
163       ['key', 'value']
    ~~~~~~~~~~~~~~~~~~~~~~
164     ]);
    ~~~~~

The project is on dependencies:

"@angular/core": "8.1.0", "immutable": "4.0.0-rc.12", "typescript": "<3.5.0", "karma": "4.1.0" and "jasmine-core": "3.4.0".

I have no idea why only npm test would fail here. My only clue is that Immutable.js used to have an Iterable interface, which has been removed since version 4.0.0, but the Map factory function in question still depends on an argument of type Iterable. Can we be sure this is the EcmaScript type?

donders
  • 3
  • 3
  • Please try this https://stackoverflow.com/questions/30019542/es6-map-in-typescript – GRS Aug 19 '19 at 12:53
  • this question is not about the ecmascript Map type, but about the Immutable.js Map type. – donders Aug 19 '19 at 12:55
  • Its not about the type. Its about how you define it in typescript. The error is coming while the transcompile is happening. Typescript's strong type check is not allowing you to define the Map which accepts only hash as a parameter – GRS Aug 19 '19 at 12:57
  • What do you mean by hash? I need to make a Map with the collection type as described in Immutable.js documentation, but that exact notation is giving the above error. – donders Aug 19 '19 at 13:15
  • To come back on this: the 2016 solution mentioned in the linked question is the exact same as the 'obj' notation of Immutable.js mentioned above, which I cannot use in the way I intend. I would like to use the 'collection' notation, which does not compile. – donders Aug 20 '19 at 10:00

1 Answers1

0

As commented on your bug report, this should be fixed in 4.0.0-rc.14

Please re-open this issue if this is not the case.

Julien Deniau
  • 4,880
  • 1
  • 18
  • 22