question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Property 'payload' does not exist on type 'Action<"__NEXT_REDUX_WRAPPER_HYDRATE__">' with latest Redux-Toolkit 1.9.0

See original GitHub issue

Describe the bug

RTK team redesigned extraReducers a bit and current approach is going to be deprecated when RTK 2.0 releases. So current implementation

extraReducers: {
    [HYDRATE]: (state, action) => {
      // ...
    },
  },

should be changed to:

extraReducers: (builder) => {
    builder.addCase(HYDRATE, (state, action) => {
      // ...
    }),
  },

But currently going that way is not possible due to the following error:

Property ‘payload’ does not exist on type ‘Action<“NEXT_REDUX_WRAPPER_HYDRATE”>’

Apparently there is no payload on action variable, only type is present.

To Reproduce

Steps to reproduce the behavior:

  1. Follow migration guide for RTK 1.9.0

Screenshots

image

Issue Analytics

  • State:open
  • Created 10 months ago
  • Reactions:5
  • Comments:6

github_iconTop GitHub Comments

10reactions
karaoakcommented, Dec 5, 2022

This is not a next-redux-wrapper issue.

As per RTK documentation (as linked to in the deprecation warning): https://redux-toolkit.js.org/api/createSlice#the-extrareducers-builder-callback-notation

You should use the the builder callback notation.

This means you should first create a typed action with the HYDRATE string const. In this way you are forced to type the payload of your action.

See below example for what your updated code should look like:

import { createSlice, createAction, PayloadAction } from '@reduxjs/toolkit';
import { AppState } from "@webapp/store";
import { HYDRATE } from '@webapp/store/next-redux-wrapper';

const hydrate = createAction<AppState>(HYDRATE);

// and then inside your createSlice options, add:

 extraReducers: (builder) => {
        builder.addCase(hydrate, (state, action) => {

You can also create an action to be shared among slices, like this:

export const APP_HYDRATE = createAction<AppState>(HYDRATE);

and instead import that into your slices.

1reaction
phatifycommented, Nov 29, 2022

give us a reproduction link describe for this issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

angular - Property 'payload' does not exist on type 'Action ...
The payload property has been removed from the Action interface. However, the example they give seems completely counter intuitive (in my view..
Read more >
Property Payload does not exist on type... #31 - GitHub
Interesting is that it seems to take the type from the first action (which indeed does not have a payload constructor). Here is...
Read more >
Usage With TypeScript - Redux Toolkit
This will result in the created action being of type PayloadActionCreator<number, string> . In some setups, you will need a literal type for ......
Read more >
react-redux-typescript-guide/typesafe-actions - Gitter
Hi, is there a way of extracting the type of an action's payload, for use in generics? I'm trying to type the function...
Read more >
Error A case reducer on a non-draftable value must not return ...
But my action.payload is well defined and redux toolkit is up to date. ... "property 'assign' does not exist on type 'ObjectConstructor'".
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found