Open
Description
What happened
When using a Map
as a key for another Map
, flow gets confused if the Map
can have multiple possible value types. Here’s the flow error:
Error: src/model/immutable/CharacterMetadata.js:113
113: [[Map(defaultRecord), CharacterMetadata.EMPTY]],
^^^^^^^^^^^^^ object type. This type is incompatible with the expected param type of
865: static <K, V>(values?: Iterable<[K, V]> | PlainObjInput<K, V>): Map<K, V>;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ union: type application of identifier `Iterable` | type application of polymorphic type: PlainObjInput. See: node_modules/immutable/dist/immutable.js.flow:865
Member 1:
865: static <K, V>(values?: Iterable<[K, V]> | PlainObjInput<K, V>): Map<K, V>;
^^^^^^^^^^^^^^^^ type application of identifier `Iterable`. See: node_modules/immutable/dist/immutable.js.flow:865
Error:
113: [[Map(defaultRecord), CharacterMetadata.EMPTY]],
^^^^^^^^^^^^^ object type. This type is incompatible with
865: static <K, V>(values?: Iterable<[K, V]> | PlainObjInput<K, V>): Map<K, V>;
^^^^^^^^^^^^^^^^ $Iterable. See: node_modules/immutable/dist/immutable.js.flow:865
Property `@@iterator` is incompatible:
865: static <K, V>(values?: Iterable<[K, V]> | PlainObjInput<K, V>): Map<K, V>;
^^^^^^^^^^^^^^^^ property `@@iterator` of $Iterable. Property not found in. See: node_modules/immutable/dist/immutable.js.flow:865
113: [[Map(defaultRecord), CharacterMetadata.EMPTY]],
^^^^^^^^^^^^^ object type
Member 2:
865: static <K, V>(values?: Iterable<[K, V]> | PlainObjInput<K, V>): Map<K, V>;
^^^^^^^^^^^^^^^^^^^ type application of polymorphic type: PlainObjInput. See: node_modules/immutable/dist/immutable.js.flow:865
Error:
31: entity: ?string,
^^^^^^^ null. This type is incompatible with
30: style: DraftInlineStyle,
^^^^^^^^^^^^^^^^ OrderedSet
How to reproduce
import { Map } from 'immutable';
type ThingStyle = Map<string, string>;
type Props = {
style: ThingStyle,
entity: ?string,
};
const defaultProps: Props = {
style: Map(),
entity: null,
};
const linkThing = Map({
style: Map({ color: 'purple' }),
entity: 'LINK',
});
const cache: Map<Map<string, any>, Map<string, any>> = Map(
[ [ Map(defaultProps), linkThing ] ],
);
If the values of the props passed to Map
are consistent, there is no flow error, as in the following:
import { Map } from 'immutable';
type Props = {
style: ?string,
entity: ?string,
};
const defaultProps: Props = {
style: '',
entity: null,
};
const linkThing = Map({
style: '',
entity: 'LINK',
});
const cache: Map<Map<string, ?string>, Map<string, ?string>> = Map(
[ [ Map(defaultProps), linkThing ] ],
);