Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Map with Typescript #1706

Closed
Gerasimov94 opened this issue Apr 26, 2019 · 6 comments
Closed

Using Map with Typescript #1706

Gerasimov94 opened this issue Apr 26, 2019 · 6 comments

Comments

@Gerasimov94
Copy link

Gerasimov94 commented Apr 26, 2019

Hello, i found an interesting issue. When i am passing an object in Map it works fine:

import {Map} from 'immutable';
...
const myMap = Map({a: 1});

But when i am trying to pass an array like on screen below, compiler complains:

const myMap = Map([[ "key", "value" ]]);

I took a that variant from here: https://immutable-js.github.io/immutable-js/docs/#/Map/Map

Argument of type 'string[][]' is not assignable to parameter of type '{ [key: string]: {}; }'. Index signature is missing in type 'string[][]'

In my opinion, it works that way because we have an overloaded Map functions at definitions file, and typescript choosing second variant instead of first.

  immutable-nonambient.d.ts: 761

  export function Map<K, V>(collection: Iterable<[K, V]>): Map<K, V>;
  export function Map<V>(obj: {[key: string]: V}): Map<string, V>;

ts version: 3.3.333333

@vamshi-tg
Copy link

Facing same problem. Created this csb for reference https://codesandbox.io/s/immutable-map-typescript-issue-56t35

@vamshi-tg
Copy link

We can resolve the typescript error with the below steps.

const strTupleArr: [string, string][] = [["key", "value"]]
const myMap = Map(strTupleArr);

@jdeniau
Copy link
Member

jdeniau commented Jun 29, 2021

Thank you for your bug report. The immutable-js oss fork will soon be merged and a fix for this issue has been included in #1833. Once this PR is merged, this issue will be resolved in the main branch. We will then do our best to to release the 4.0.0 version.

jdeniau added a commit that referenced this issue Jun 29, 2021
jdeniau added a commit that referenced this issue Jun 29, 2021
@jdeniau
Copy link
Member

jdeniau commented Jul 8, 2021

Hi!
The 4.0.0-rc.14 version has been released and should fix this issue.
Feel free to test it and re-open this issue if the issue is still present.
Thank you!

@jdeniau jdeniau closed this as completed Jul 8, 2021
@ClusterH
Copy link

faced same error even though tried use 4.0.0-rc.14

@jdeniau
Copy link
Member

jdeniau commented Nov 30, 2021

@ClusterH can you try with the stable 4.0.0 and post a reproducible code snippet if there is the error is still present?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants