Skip to content

Root state properties being typed as never with redux 4.0.5. #3690

Closed
@ryan-rushton

Description

@ryan-rushton

Do you want to request a feature or report a bug?

bug

Prior Issues

Not that I am aware of

Bug Reports

What is the current behavior?

I am seeing root state properties being typed as never instead of getting a compilation error for mismatching types.

Steps to Reproduce

Basically when using typescript and combineReducer, if you are not using the slice function and instead creating pure function reducers, the types or the returned rootState are set to never. Being new to this library I got tripped up on this.

Downgrading to redux 4.0.4 gives different results depending on environment:

  • Here in this Code Sandbox we see the type error produced with 4.0.4 and never with 4.0.5.
  • In my local project running in VS Code I get the correct types coming through with 4.0.4 and never with 4.0.5.

I realise I didn't set up properly and the redux-toolkit docs strongly suggest to use createSlice with typescript, but I think this could point to an issue with the types. Also I was stumped for quite a while trying to figure out what the issue was, so if someone else has this hopefully this issue can point them in the right direction.

Finally using createSlice from redux toolkit fixes this issue.

What is the expected behavior?

To get either type errors or the return type of my reducers as root state properties

Environment Details

OSX Latest, VS Code and VS Code Insiders, Typescript as per the demo above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions