I want to have an ImmutableJS Map which has to have always defined some properties:
interface MyImmutableMap extends Immutable.Map<string, any> {
a: number;
b: number;
c?: string;
}
I have a function which edits the map:
function myFunction(myMap: MyImmutableMap, flag: boolean, value: number): MyImmutableMap {
if (flag) {
return myMap
.set('a', value);
}
return myMap;
}
The second return is ok, because it returns the same thing I received, therefore an MyImmutableMap.
Unfortunately the set() doesn't work, because its return type is a Map and not the type of myMap.
This is the error:
Type 'Map' is not assignable to type 'MyImmutableMap'.
Property 'a' is missing in type 'Map'.
There is any way to go around this?