Skip to content

Using Map with Typescript #1706

Closed
Closed
@Gerasimov94

Description

@Gerasimov94

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions