I have angular2 app and i'm using immutable.js
. When i use user Map
function from immutable
typescript compiler gets stuck. When i don't import the typing from immutable.js
it works fine but i get errors for every function that i use from `immutable.js.
import {Map} from 'immutable';
this is the line that blocks typescript.
The Map
from immutable.js may conflict with TypeScript's internal Map
. To resolve the collision, you can try something like import {Map} as MyMap from 'immutable'
and use MyMap
in your code.
You could also use import * as Immutable from 'immutable'
and access features in the Immutable
namespace.
I have use immutable version 3.8.2 and it 's woring correcly with typescript.
import {Map} from 'immutable';
const map1 = Map( {a: 1, b: 4, c: 3 })
const map2 = map1.set('b', 2)
stackblitz typescript demo
Import map function like this import {Map} from 'immutable';
will conflict with javascript ES2015 Map so you cant use both of theme to solve this you can use another variable or alias to hold immutable map function like this
import {Map as _map} from 'immutable';
const map1 = _map( {a: 1, b: 4, c: 3 })
const map2 = map1.set('b', 2)
you can import entire immutable module mean all immutable function like this
import * as immutable from 'immutable';
const map1 = immutable.Map( {a: 1, b: 4, c: 3 })
const map2 = map1.set('b', 2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With