To sum up, the big change in 5.0 is a Typescript change related to Map that is typed closer to the JS object. This is a huge change for TS users, but do not impact the runtime behavior. (see Improve TypeScript definition for Map for more details)
Other breaking changes are:
[BREAKING] Remove deprecated methods:
Released in 5.0.0-rc.1
Map.of('k', 'v'): use Map([ [ 'k', 'v' ] ]) or Map({ k: 'v' })
Collection.isIterable: use isIterable directly
Collection.isKeyed: use isKeyed directly
Collection.isIndexed: use isIndexed directly
Collection.isAssociative: use isAssociative directly
Collection.isOrdered: use isOrdered directly
[BREAKING] OrdererMap and OrderedSet hashCode implementation has been fixed
Released in 5.0.0-rc.1
Fix issue implementation of hashCode for OrdererMap and OrderedSet where equal objects might not return the same hashCode.
Immutable does not export a default object containing all it's API anymore.
As a drawback, you can not immport Immutable directly:
- import Immutable from 'immutable';
+ import { List, Map } from 'immutable';
- const l = Immutable.List([Immutable.Map({ a: 'A' })]);
+ const l = List([Map({ a: 'A' })]);
If you want the non-recommanded, but shorter migration path, you can do this:
- import Immutable from 'immutable';
+ import * as Immutable from 'immutable';
const l = Immutable.List([Immutable.Map({ a: 'A' })]);
[TypeScript Break] Improve TypeScript definition for Map
Released in 5.0.0-beta.1
If you do use TypeScript, then this change does not impact you : no runtime change here.
But if you use Map with TypeScript, this is a HUGE change !
Imagine the following code
const m = Map({ length: 3, 1: 'one' });
This was previously typed as Map<string, string | number>
and return type of m.get('length') or m.get('inexistant') was typed as string | number | undefined.
This made Map really unusable with TypeScript.
Now the Map is typed like this:
MapOf<{
length: number;
1: string;
}>
and the return type of m.get('length') is typed as number.
The return of m.get('inexistant') throw the TypeScript error:
Argument of type '"inexistant"' is not assignable to parameter of type '1 | "length"
If you want to keep the old definition
This is a minor BC for TS users, so if you want to keep the old definition, you can declare you Map like this:
Like a simple object, it will only work if the type is forced:
Map<{ a: string; b?: string }>({ a: 'a' }).set('b', 'b'); // b is forced in type and optional
Map<{ a?: string }>({ a: 'a' }).delete('a'); // you can only delete an optional key
Are all Map methods implemented ?
For now, only get, getIn, set, update, delete, remove, toJS, toJSON methods are implemented. All other methods will fallback to the basic Map definition. Other method definition will be added later, but as some might be really complex, we prefer the progressive enhancement on the most used functions.
Fixes
Fix type inference for first() and last() #2001 by @butchler
Fix issue with empty list that is a singleton #2004 by @jdeniau
Map and Set sort and sortBy return type #2013 by @jdeniau
Internal
[Internal] Migrating TS type tests from dtslint to TSTyche#1988 and #1991 by @mrazauskas.
Special thanks to @arnfaldur that migrated every type tests to tsd just before that.