Skip to content

Type 'Data' is not assignable to type 'WritableDraft<Data>' After UI Library Update #4900

Closed
@yusufdeepwork

Description

@yusufdeepwork

Description:
Hi,

I am facing an issue with Redux Toolkit (v1.8.1) and TypeScript after updating a UI library in my project as a minor version update. After the update, I started receiving the following TypeScript error across all slice files:

Type 'Data' is not assignable to type 'WritableDraft<Data>'.
Types of property 'filters' are incompatible.
Type 'Data2[]' is not assignable to type 'WritableDraft<Data2>[]'

Steps to Reproduce:

  1. Update UI library a minor version update.
  2. Use Redux Toolkit (v1.8.1) to manage state with TypeScript.
  3. Trigger the state update via a reducer function, such as:
    setData: (state, { payload }: { payload: Data }) => {
      state.filter = payload;
    }
  4. Encounter the error:
    Type 'Data' is not assignable to type 'WritableDraft<Data>'.
    

Environment:

  • Redux Toolkit Version: v1.8.1
  • React Version: 18.x
  • Node Version: 18.18.0
  • Immer Version: 9.0.21
  • React-Redux Version: 8.1.3
  • TypeScript Version: 4.9.4
  • Bundler: Rollup (with configuration as follows)

Possible Cause:

The error appears after updating the UI library, which may have caused a type mismatch between Data and WritableDraft<Data>. The error message specifically mentions an issue with the filters property, where a Data2[] type is being assigned to a WritableDraft<Data2>[].

I also believe that the Rollup configuration in the UI library may be affecting my project. Since the update, I am experiencing this issue in all my slice files where I use Redux Toolkit. Despite having no issues before the update, now every slice file that uses Redux Toolkit and Immer is throwing the same TypeScript error.

Expected Behavior:

There should be no type compatibility issue, and the code should compile without errors after the UI library update.

What I Have Tried:

  1. Checked and compared the changes in the UI library between versions.
  2. Updated TypeScript configuration and dependencies to ensure compatibility.
  3. Reverted some changes to see if the error persists.
  4. Tried adjusting the state mutation approach, but the error persists.
  5. Double-checked Rollup config in the UI library and found no immediate impact on the Redux Toolkit setup, but the errors persist.

Additional Information:

  • Rollup configuration in the UI library was modified, and this might be affecting the types used by Redux Toolkit in my project. I am experiencing these issues across all slice files, which suggests that the Rollup configuration might be causing an issue with module resolution or type inference in TypeScript.
  • Rollup might be modifying or bundling the modules in a way that conflicts with TypeScript's type inference in Redux Toolkit.
  • No similar issues have been observed with previous versions of the UI library.
  • The UI library update may have affected the types or dependencies that Redux Toolkit relies on.

What I Am Asking For:
I would appreciate any guidance or solutions to resolve this TypeScript type compatibility issue, especially with respect to how Rollup configuration could be influencing Redux Toolkit's behavior in my project. If this is a known issue with Redux Toolkit or Rollup, any suggestions on how to fix or workaround this problem would be helpful.

Thank you!


Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions