Skip to content
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

Destructuring reducer action parameter => Wrongly ActionCreatorWithOptionalPayload while strict is set to true #4559

Open
RobIsHere opened this issue Aug 13, 2024 · 2 comments

Comments

@RobIsHere
Copy link

I've seen all the other issues and double checked that "strict": true is in my tsconfig.json
"typescript": "^4.9.5" with up to date create react app setup

This Works as part of a slice and the created action creator becomes ActionCreatorWithPayload

switchAccessory: (state, action: PayloadAction<{ item: Accessory; isSelected: boolean }>) => {
  if (action.payload.isSelected) {
    if (!state.accessories.some((x) => x.id === action.payload.item.id)) {
      // Add accessory if not already there
      state.accessories.push(action.payload.item);
    } else {
      // Add accessory if not already there
      state.accessories.push(action.payload.item);
    }
  }
},

This does not work and the action creator becomes ActionCreatorWithOptionalPayload

switchAccessory: (state, { payload }: PayloadAction<{ item: Accessory; isSelected: boolean }>) => {
  if (payload.isSelected) {
    if (!state.accessories.some((x) => x.id === payload.item.id)) {
      // Add accessory if not already there
      state.accessories.push(payload.item);
    } else {
      // Add accessory if not already there
      state.accessories.push(payload.item);
    }
  }
},
@EskiMojo14
Copy link
Collaborator

I can't replicate this in the playground - does this happen when you run TSC, or just in your IDE? Which IDE are you using?

@RobIsHere
Copy link
Author

Thanks for looking into this. The error was in both, on the webpack typescript compiler in the devserver. And additionally it was shown in VS Code.

I can try to make a reproduction, but it will take some time because I'm super busy with a tight work project timeline right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants