You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When calling .sort() or .sortBy() on non-"Ordered" Collections like Maps and Sets, the return type is the same as the original Collection, when it actually returns the "Ordered" version.
However, I don't know enough to recommend that as the real fix. This issue probably also affects some other types besides just Map and Set, and it might be better to add the accurate definitions on one of the abstract types, or some other interface. 🤷
How to reproduce
Call .sort() or .sortBy() on a Map or Set and look at the returned type.
The text was updated successfully, but these errors were encountered:
Thanks for the report. I think that the fix should be easy in the TS definition file.
We should override the function definition in Map, Set etc. interface, just like you did in your example.
If you are willing to open a PR, that would be great, otherwise I will try to implement this when I'm back home.
What happened
When calling
.sort()
or.sortBy()
on non-"Ordered" Collections like Maps and Sets, the return type is the same as the original Collection, when it actually returns the "Ordered" version.According to the docs:
immutable-js/type-definitions/immutable.d.ts
Lines 4570 to 4582 in 0c2d021
This matches the implementations:
immutable-js/src/Map.js
Lines 112 to 120 in 0c2d021
immutable-js/src/Set.js
Lines 153 to 161 in 0c2d021
However the TS types just use the inherited definitions from
interface Collection<K, V>
:immutable-js/type-definitions/immutable.d.ts
Line 4589 in 0c2d021
immutable-js/type-definitions/immutable.d.ts
Lines 4612 to 4615 in 0c2d021
It's possible to monkey-patch the Map and Set interfaces like this:
However, I don't know enough to recommend that as the real fix. This issue probably also affects some other types besides just Map and Set, and it might be better to add the accurate definitions on one of the abstract types, or some other interface. 🤷
How to reproduce
Call
.sort()
or.sortBy()
on a Map or Set and look at the returned type.The text was updated successfully, but these errors were encountered: