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

Fix type signature of update and mapEntries #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fix type signature of update and mapEntries #9

wants to merge 1 commit into from

Conversation

conartist6
Copy link
Member

Porting this PR from the unforked repo.

@conartist6
Copy link
Member Author

Interesting, it seems to be an undocumented feature of mapEntries that it can also filter if you do not return an entry from the mapper. Hence that change.

@Methuselah96
Copy link

I imagine we should also update the other instances of update (Map) and mapEntries (Keyed).

Comment on lines +404 to +405
update(index: number, notSetValue: T, updater: (value: T | undefined) => T): this;
update(index: number, updater: (value: T | undefined) => T): this;
Copy link

@Methuselah96 Methuselah96 Aug 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how I feel about this change. TypeScript doesn't return T | undefined for arrays and I'm wondering if this is similar. I feel like this would be inconvenient if the user knows that the type is not undefined. I would be interested in seeing common use cases of the update function.

@conartist6 What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So one easy improvement is that if notSetValue is given then the value passed to updater will never be undefined.

I think immutable should strive to be more correct than plain array access, and that is what most of the types, e.g. get(), do.

@@ -1345,7 +1345,7 @@ declare module Immutable {
* @see Collection.Keyed.mapEntries
*/
mapEntries<KM, VM>(
mapper: (entry: [K, V], index: number, iter: this) => [KM, VM],
mapper: (entry: [K, V], index: number, iter: this) => [KM, VM] | undefined,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should document the filtering behavior?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, yes.

@jdeniau
Copy link

jdeniau commented Jul 6, 2021

Superseeded by immutable-js#1842

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

Successfully merging this pull request may close these issues.

3 participants