-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
createSlice causing a TS Compiler error: "This is likely not portable, a type annotation is necessary" #790
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
Comments
Ok, maybe not a red-alarm, this error only appears on VS Code for some reason (?) when I do Still, I'd really rather not see this at all, so any feedback would be helpful. |
If I had to guess this might be because you have multiple versions of immer installed in your repository, so the inferred type references But that's really just a guess :/ |
@Vassi @phryneas I'm seeing this as well. I think this may be similar to this issue: Fundamentally, |
As far as I know, "exporting the whole lib" isn't relevant here. TS should be able to follow Immer's types into what's included with Immer itself. |
@lafritay Most of the time that seems to be the case because you have multiple different versions of immer installed in your application and the types of these might be conflicting with each other. Can you check that? |
@markerikson @phryneas I double-checked my dependencies - I did have a direct dependency on To confirm something odd wasn't happening here, I dropped my direct dependency on After debugging some more, I found the issue - or at least a workaround. I had been importing It seems like the issue will come back if I need to use anything from the |
@lafritay that doesn't mean that something else did not install another version of immer. React-scripts seem to cause that oftentimes for example. Try a |
I think I had a corrupted version of immer or rtk in my And after removing my direct dependency on it to see if that was masking it somehow: Blowing away my I appreciate the help working through this. Update: On digging into this more trying to recreate it, I found that it is a problem with I'm not enough of an npm wizard to understand what makes that segment show up or go away though. The only other entry in that file related to immer is this: |
Had the same issue in a lerna repo, fixed it by adding |
Ah, so you resolved immer to a single version at the root of your monorepo. |
FWIW, I had this problem with my project which uses Bazel and
|
Fairly new to TS, and I had this slice working before we decided to switch to TS and suddenly I found myself wrestling with several bears at once when it comes to some of the typings for createSlice and createAsyncThunk.
I thought I had everything sorted and then noticed one final compiler error on authSlice:

I have to admit I have 0 clue what this is expecting of me.
The text was updated successfully, but these errors were encountered: