TypeScript: Nightly bug(?) with infering function generic while being part of intersection
First of all, the title exists for the sake of a title. I don’t really know exactly what is wrong with this bug. I came across this while working on something with redux tookit.
Error: Parameter 'state' implicitly has an 'any' type.
Expected: state = WritableDraft<{username: string, isLoggedIn: true, ...}>
I am using the nightly extension and the bug has not occured because of an update to redux toolkit or a change in my code, but has instead been because of typescript versions changing. The code itself works in typescript 4.7.0 but not in typescript nightly/4.8.0
In order to create a minimum reproducible example, I have tried to simplify it as much as possible, (which was harder than I imagined). The problem is rather weird, there are multiple parts that cause this bug and removing any will fix it. However, the issue remains, version 4.7.0 works while the same on nightly errors.
At this point, I still do not know exactly what the problem is. In fact, it may even be intentional. However, this is something that breaks redux toolkit so I think the matter is something worth taking a look at.
What search terms have I used? None. I don’t know how to put this bug into words.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 27 (13 by maintainers)
Taking possible red herrings out of the repro:
aisstringin 4.7 and implicit any in 4.8 and I don’t see a good reason for that to have changed.Yeah. We have both unit tests, and a set of “type tests”.
to run them:
Hi, I’m another Redux Toolkit maintainer. Wanted to follow up on this.
Lenz has put together a potential workaround on our side, but it requires what is frankly a pretty ugly hack (a separate package that abuses
typesVersionsto figure out what TS version we’re dealing with, and changing what ourcreateSlicetype includes based on that).Any thoughts on whether this issue is something the TS team intends to address before 4.8 is released?
The change between v4.7.4 and main occurred at 9236e39374c0ec9a1e3f9894af4fb9eb34ba0021.