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
TypeScript: ReadonlyMap & ReadonlySet not available when targeting es5
#624
Comments
A long long time ago, we had our own typings for those collections, but that bring their own problems, like our types being sooner or later not assignable to anything that accepts real maps and sets, missing newer browser API's etc. I recommend rather, that in the case you don't have ES2015 collections available in your TS set, to declare the types you suggest above somewhere in a For all clarity, if you are using Map and Set, I think ES2105.collections is quite a correct thing to do? |
This is a problem not we ourselves are experiencing, but some of our users. So they have to fix it on their side, which is unfortunate.
That would essentially require a breaking change in the DOM APIs, so it's highly unlikely. New properties would not pose a problem as the types I suggested above would only be used by TS for pattern matching against the real object types, not replace them in any way. (As long as
This error is happening regardless of Maps and Sets actually being used (in the linked example, it's a |
Feel free to submit a PR to work out ideas, but I think if we redefine Map, we potentially break it for any existing ES2016... ES2XXX user as their drafts would become only subset of what is available now in their environment. If I understand your solution correctly. (e.g. a draft map might suddenly not have an iterator anymore etc). You could also check if it possible to check in the immer utility first if Map isn't an empty type (e.g. |
I believe overriding the global The thing is: TypeScript doesn't care about the names of these interfaces and just does pattern matching, so declaring an interface I'll try to open a PR some time in the next week. |
🎉 This issue has been resolved in version 7.0.11 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🐛 Bug Report
We had this as a bug report in redux-toolkit, but it boils down to immer.
If the
target
is set toes5
, the"ES2015.Collection"
library is not loaded by TypeScript, soReadonlyMap
andReadonlySet
are not available. This leads to theDraft
type spinning into an endless recursion (asReadonlyMap
is interpreted as the empty object type, matching everything), resulting in aDraft
type likefor the most simple drafted objects.
A simple fix would be to not rely on the external definitions of
ReadonlyMap
andReadonlySet
, but just to include them, which would mean definingnext to the
Draft
type.If this would be a welcome addition, I'd be happy to open a PR :)
Link to repro
A very simple reproduction can be found on https://github.com/jon-thompson/rtk-map-issue
Environment
We only accept bug reports against the latest Immer version.
setUseProxies(true)
setUseProxies(false)
(ES5 only)The text was updated successfully, but these errors were encountered: