add simple test to reproduce groupBy regression#2100
add simple test to reproduce groupBy regression#2100jdeniau merged 1 commit intoimmutable-js:mainfrom
Conversation
|
Hi, Thanks for the bug report. I added that because I trusted typescript, but as immutable accept any value as key, having See https://immutable-js.com/play/#IE1hcChbW3VuZGVmaW5lZCwgJ2EnIF1dICkKLmdldCh1bmRlZmluZWQp TS might be more strict on undefined values though. I will check that, but it's clearly a regression. |
It seems reasonable to assert that keys shouldn't be undefined, since keys are supposed to be of type PropertyKey (string | number | symbol). But in practice, JavaScript allows undefined as a key by implicitly converting it to the string "undefined". This caused a regression specifically in the `groupBy` function, where the grouper callback can return undefined for some items. That behavior was previously supported and is now broken by the assertion. Long-term, it probably makes sense to tighten this up and only allow real PropertyKeys, but that’ll need a more careful cleanup.
|
Hi, Thanks for your quick answer. I added a quick fix and a test that caught the regression. Used Long-term, it might make more sense to disallow undefined keys and introduce a breaking change. As this is more in line with how typescript works. |
|
Output diff failing test is under control as we change a TS file that does change the builded output. |
|
Thanks, this has been released in 5.1.2 |
Hello,
While updating our codebase to the latest version of Immutable, we encountered what seems to be a regression in the behavior of
groupBy.This change was introduced in Commit 53237d2.
Previously, grouping by a function that might return
undefinedwas tolerated, but in the latest version, this now throws. While the new behavior arguably makes sense—since grouping byundefinedisn’t very clean—it does appear to be a breaking change, violating semantic versioning.If this change is considered intentional, it should also be reflected in the type system: the
grouperfunction should not be allowed to returnundefined.We’d like to clarify the intended direction:
Thanks in advance for your guidance, and thanks for maintaining the project!