8000 add simple test to reproduce groupBy regression by giggo1604 · Pull Request #2100 · immutable-js/immutable-js · GitHub
[go: up one dir, main page]

Skip to content

add simple test to reproduce groupBy regression #2100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions __tests__/groupBy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ describe('groupBy', () => {
expect(group.toJS()).toEqual({ odd: [1, 3, 5], even: [2, 4, 6] });
});

it('allows `undefined` as a key', () => {
const group = Seq([1, 2, 3, 4, 5, 6]).groupBy((x) =>
x % 2 ? undefined : 'even'
);
expect(group.toJS()).toEqual({ undefined: [1, 3, 5], even: [2, 4, 6] });
});

it('groups indexed sequences, maintaining indicies when keyed sequences', () => {
const group = Seq([1, 2, 3, 4, 5, 6]).groupBy((x) => x % 2);

Expand Down
14 changes: 7 additions & 7 deletions src/functional/updateIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,11 @@ function updateInDeeply<
}
const key = keyPath[i];

if (typeof key === 'undefined') {
throw new TypeError(
'Index can not be undefined in updateIn(). This should not happen'
);
}
const nextExisting = wasNotSet
? NOT_SET
: // @ts-expect-error key might be undefined which is not allowed in the type but works in practice
get(existing, key, NOT_SET);

const nextExisting = wasNotSet ? NOT_SET : get(existing, key, NOT_SET);
const nextUpdated = updateInDeeply(
nextExisting === NOT_SET ? inImmutable : isImmutable(nextExisting),
// @ts-expect-error mixed type
Expand All @@ -196,10 +194,12 @@ function updateInDeeply<
notSetValue,
updater
);

return nextUpdated === nextExisting
? existing
: nextUpdated === NOT_SET
? remove(existing, key)
? // @ts-expect-error key might be undefined which is not allowed in the type but works in practice
remove(existing, key)
: set(
wasNotSet ? (inImmutable ? emptyMap() : {}) : existing,
key,
Expand Down
Loading
0