{{ message }}
better types 6.x - #2204
Merged
Merged
better types 6.x#2204
Conversation
jdeniau
marked this pull request as ready for review
June 1, 2026 16:21
jdeniau
pushed a commit
to jdeniau/immutable-js
that referenced
this pull request
Aug 16, 2026
Each finding from .agents/migration-status.md was traced back to its originating PR, then fixed or confirmed as an intentional change: - R1 (isSubset string argument, from immutable-js#2204): keep the new character-iteration semantics, consistent with isSuperset and with Collection('abc'); documented as a v6 breaking change in the CHANGELOG and pinned by multi-char unit tests. - R2 ('@@iterator' fallback removal, from immutable-js#2127): confirmed intended modernisation; explicit CHANGELOG entry, and the two immutable.d.ts docstrings no longer mention @@iterator. immutable.js.flow is left untouched since Flow's @@iterator syntax denotes Symbol.iterator. - R3 (reverseFactory reverse-iteration keys, ?? 0 from immutable-js#2206, NaN keys already in v5): fixed by counting down from the number returned by ensureSize(collection) - the reversed sequence has the same size as its source. Regression tests cover both __iterate (reduceRight) and __iterator (keyed reverse) paths; CHANGELOG entry since the NaN behaviour shipped in v5. - R4 (wholeSlice with begin === undefined, from immutable-js#2128): restored the faithful v5 form (begin !== undefined && begin <= -size) so slice() with no arguments goes through sliceFactory again, on empty collections too; identity regression test added. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0122shfP2ngkkjuXZBWoeFGW
jdeniau
pushed a commit
to jdeniau/immutable-js
that referenced
this pull request
Aug 16, 2026
Each finding from .agents/migration-status.md was traced back to its originating PR, then fixed or confirmed as an intentional change: - R1 (isSubset string argument, from immutable-js#2204): keep the new character-iteration semantics, consistent with isSuperset and with Collection('abc'); documented as a v6 breaking change in the CHANGELOG and pinned by multi-char unit tests. - R2 ('@@iterator' fallback removal, from immutable-js#2127): confirmed intended modernisation; explicit CHANGELOG entry, and the two immutable.d.ts docstrings no longer mention @@iterator. immutable.js.flow is left untouched since Flow's @@iterator syntax denotes Symbol.iterator. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0122shfP2ngkkjuXZBWoeFGW
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Improves the TypeScript types of
Collection.tsas part of the ongoing TS migration, removing hand-writtenascasts and@ts-expect-errorsuppressions in favour of properly inferred types.findand related accessorsNSV(not-set value) type parameter tofind, and typefindEntry'snotSetValueas[K, V].find,get,has,firstandlast(as V | undefined,as unknown as V, …) and remove a@ts-expect-erroronnotSetValue.isSubset/isSupersetas unknown as { … }/as unknown as CollectionImplcasts with a smallhasIncludesMethodtype guard.isSupersetasCollection(iter).every((value) => this.includes(value)), which is behaviourally equivalent to the previousiter.isSubset(this)delegation but removes thethis as unknown as Iterable<V>cast (isSubsetis not overridden anywhere, so there was no polymorphism to preserve).typeof iter === 'object'before usingin, so passing a primitive iterable (e.g. astring) no longer throws.Behaviour change:
isSubset/isSupersetnow normalize non-Immutable inputs throughCollection()(based onisCollection) instead of duck-typing an arbitraryincludes/isSubsetmethod. A plain object that is not an Immutable collection but exposes its ownincludes/isSubsetmethod will no longer have that method invoked — it is treated as a regular iterable. Immutable collections and arrays are unaffected.reduce/reduceRightreducehelper generically, removing the@ts-expect-errorand theas Rcast at both call sites. The implementation signature now returns the honestV | R | undefined(the public overloads still returnR).Array#reduce-style overload for the no-initial case where the accumulator is a value (R = V), so the result type is inferred from the collection's values instead of requiring an explicit type argument:list.reduce((a, b) => a + b)now infersnumber.Tests
reduce/reduceRight(none existed before): result type with/without an initial value, the new value inference, and the reducer argument types acrossList,Map,SetandCollection.isSubsetagainst arrays/collections and a primitivestring(regression for theinthrow), andreducewithout an initial value (single value returns the seed, empty collection returnsundefined).CHANGELOG.mdupdated for the user-visible behaviour and type changes.