Closed
Description
What happened
update(key: K, updater: (value: V) => V): this;
here updater
has wrong type, should be updater: (value?: V) => V)
if key doesn't exist
How to reproduce
const good = I.Map<string, I.List<string>>().update("noKey", I.List(), a => a.map(x => x));
const bad = I.Map<string, I.List<string>>().update("noKey", a => a.map(x => x));
const fixed = I.Map<string, I.List<string>>().update("noKey", undefined as any, (a: undefined | I.List<string>) => a.map(x => x));
Here good
works as expected, fixed
shows error message that I would expect to see in this case Object is possibly 'undefined'
, but bad
doesn't show any errors while crashing at run time with Uncaught TypeError: Cannot read property 'map' of undefined
Maybe there need to be a function that is updateIfKeyExist
that would have (value: V) => V
type, but right now type is misleading and causes run time issues.