-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Improve scalability of Immutable.Map TS types #1831
Comments
Is there a reason you're not using |
@Methuselah96 Record is indeed a good way to handle this, however, there are cases where Map has to be preferred. The signature for update<K>(key: K, updater: (value: TProps[K]) => TProps[K]): this vs: update(key: K, notSetValue: V, updater: (value: V) => V): this
update(key: K, updater: (value: V) => V): this
update<R>(updater: (value: this) => R): R Significantly, the 3rd overload of |
My team had/has the same issue; Records didn't exist when we started using Immutable, so turning objects into Maps was the only choice. We also weren't using TS yet, so this wasn't a problem. I can tell you from experience that translating a Map-based code base into Record-based takes time, but the effort is pretty straightforward and definitely worth it if you can afford the person-hours. As for the types themselves, the best we could come up with is The frustrating bit which could probably be improved is that during the switch from using Map to using Record, there are many places that can accept either, and use them the same way at runtime, but the types don't match. e.g.:
|
Interesting. My team hasn't run into this, we generally use |
(I'm not claiming to be an authority on Immutable, just a humble user with a few years experience, during which this Map vs Record stuff has caused plenty of headaches.) |
Thanks for the input everyone! Sounds like one actionable item is updating the |
Ad I remember, the only performance optimized immutable data structures is |
Hi @mbullington There is a PR opened on the fork we made : immutable-js-oss#209 It fixes some issues listed here (not the update though, but some of the |
To be more specific : @mbullington your first solution is implemented by #1837 and released in I'm closing this |
I'll try taking a look. Thanks a ton! @jdeniau |
Closing as we are now talking in #1841 |
Hello! @immutable-js/maintainers @Methuselah96
We currently use Immutable.js pretty extensively in a Redux store and are progressively moving to TypeScript. In trying to strongly type our
Immutable.Map
objects, I settled for the time being on this:It's less than ideal for strongly typing our stores, and given the option something like this would be great:
Is this something Immutable.js would be interested in for the v4.0.0 release? Happy to help with this work as long as devs find it reasonable.
I may need some TS help with overloading generics, if that's even possible. Would anyone know about the feasibility of this?
Best,
The text was updated successfully, but these errors were encountered: