Skip to content
This repository was archived by the owner on Jul 23, 2021. It is now read-only.

Wrong typescript declarations for update method #66

Open
Methuselah96 opened this issue Oct 17, 2020 · 0 comments
Open

Wrong typescript declarations for update method #66

Methuselah96 opened this issue Oct 17, 2020 · 0 comments

Comments

@Methuselah96
Copy link

From @JLarky on Sat, 23 Dec 2017 03:01:10 GMT

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));

image

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.

Copied from original issue: immutable-js#1466

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant