Migrate mixin operations to real TypeScript class methods in Collection.ts - #2193
Merged
Conversation
jdeniau
force-pushed
the
extract-mixin-simple-functions
branch
from
May 28, 2026 21:30
f998274 to
caa2c38
Compare
jdeniau
force-pushed
the
extract-mixin-operations
branch
5 times, most recently
from
May 29, 2026 09:48
eb98970 to
9610e04
Compare
jdeniau
force-pushed
the
extract-mixin-operations
branch
from
May 31, 2026 19:15
0d23ac2 to
c1aa7c7
Compare
jdeniau
force-pushed
the
extract-mixin-operations
branch
3 times, most recently
from
June 1, 2026 17:20
485786d to
c313118
Compare
The base `toIndexedSeq`/`toKeyedSeq`/`toSetSeq` were declared as returning the loose `CollectionImpl<K, V>`, which forced `as unknown as` casts in `keySeq`/`valueSeq`. Declare them with their concrete return types and route `toSeq` through the subclasses, where the key type is fixed by the class, so no assertion is needed. - Narrow the three `to*Seq` declarations to IndexedCollectionImpl<V> / KeyedCollectionImpl<K, V> / SetCollectionImpl<V>. - Distribute `toSeq` into IndexedCollectionImpl / SetCollectionImpl overrides (concrete K) and keep the keyed case on the base — no casts. - Annotate the identity `to*Seq` overrides in Seq.js via JSDoc @returns so the Seq classes satisfy the tightened types (type-only, runtime unchanged). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
jdeniau
force-pushed
the
extract-mixin-operations
branch
2 times, most recently
from
June 1, 2026 20:40
4c79bfe to
c901901
Compare
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.
Summary
Follows #2192 and builds on the
Operations.jssplit (#2194). Migrates a largebatch of mixin methods out of
CollectionImpl.jsinto real TypeScript classmethods on the
Collection.tsclasses — a concrete step toward deletingsrc/utils/mixin.ts.What changed
Real class methods (no longer mixin entries) on
CollectionImpl/KeyedCollectionImpl/IndexedCollectionImpl:map,toSeq,filter,filterNot,partition,reverse,slice,sort,sortBy,flatMap,flatten,max/maxBy/min/minBy,skip/skipLast/skipWhile/skipUntil,take/takeLast/takeWhile/takeUntil,butLast,rest,count,findLast/findLastEntry/findLastKey/findLastIndex,lastKeyOf/lastIndexOf,last,keySeq/valueSeq,flip,findIndex/indexOf,interpose/interleave,zip/zipAll/zipWith. Implementations delegate to theoperations/factoriesoperations/helpersfunctions (import-safe — no eval-timeextends, noMapimport, so no load-order cycle).
Removed the temporary interface declaration merging for
map/toSeq: thereal method bodies now carry the types directly.
IS_*_SYMBOLbrands are real runtime props assigned on the prototypes inCollection.ts(IS_COLLECTION_SYMBOL,IS_KEYED_SYMBOL,IS_INDEXED_SYMBOL,IS_ORDERED_SYMBOL). They make the otherwise structurally-identical emptysubclasses distinct, which fixes
thiscollapsing toneverintoSeq'sisIndexed/isKeyednarrowing, and they are whatisKeyed/isIndexed/… testat runtime. They must live on the prototype (not as class fields) because
makeSequenceusesObject.create(prototype)and bypasses the constructor.Every overload is preserved (e.g.
filter/partitiontype-guard overloads,flatMapindexed-vs-keyed,flattennumber-vs-boolean, thezipfamily arityoverloads), with a single loose implementation signature — matching the
hand-written
type-definitions/immutable.d.ts.Migration guide updated (
.agents/commands/migrate-to-ts.md): added a stepdocumenting overload preservation.
CollectionImpl.jsshrinks accordingly; the 3mixin(...SeqImpl, ...)calls andthe conversion/aggregation methods that still depend on
operations/sequences.js(eval-time
extends) andoperations/aggregations.js(importsMap) areintentionally left for a later PR.
Tests
are exercised through concrete types:
__tests__/List.ts(indexed helpers +edge cases),
__tests__/Map.ts(keyed variants),__tests__/toSeq.ts.type-definitions/ts-tests/collection.tscovers returntypes and overloads across List/Map/Set/Seq, including type-guard narrowing,
the
ziptuple arities,flip, and error cases (indexed-only methods on keyedcollections).
src/Collection.tsline coverage ~97% (remainder = abstract__iterate/__iteratorstubs, unreachable from the public API).Test plan
npm run type-check— 0 errorsnpm run test:unit— greennpm run test:types— greennpm run lint/npm run format— clean