Skip to content
This repository has been archived by the owner on Jul 23, 2021. It is now read-only.

Using Map with Typescript #134

Open
Methuselah96 opened this issue Oct 17, 2020 · 0 comments
Open

Using Map with Typescript #134

Methuselah96 opened this issue Oct 17, 2020 · 0 comments

Comments

@Methuselah96
Copy link

From @Gerasimov94 on Fri, 26 Apr 2019 14:26:38 GMT

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

Copied from original issue: immutable-js#1706

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

No branches or pull requests

1 participant