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

combineReducer has incorrect return type when given a custom action #4764

Open
OliverJAsh opened this issue Jan 17, 2025 · 0 comments · May be fixed by #4765
Open

combineReducer has incorrect return type when given a custom action #4764

OliverJAsh opened this issue Jan 17, 2025 · 0 comments · May be fixed by #4765

Comments

@OliverJAsh
Copy link
Contributor

Prior Issues

Not that I could find unfortunately.

I plan to submit a PR to fix this.

What is the current behavior?

Unexpected type error when exactOptionalPropertyTypes is enabled:

import { type Reducer, combineReducers } from 'redux';

type MyAction = { type: 'foo' };

type State = string;
declare const nested: Reducer<State, MyAction>;

type Combined = { nested: State };

// ❌ Error
// Type 'Reducer<{ nested: string; }, MyAction, Partial<{ nested: never; }>>' is not assignable to type 'Reducer<Combined, MyAction, Partial<Combined>>'.
//   Type 'string' is not assignable to type 'never'.
const combined: Reducer<
  Combined,
  MyAction,
  Partial<Combined>
> = combineReducers({ nested });

This only happens when using a custom action type, i.e. changing MyAction to the Redux Action type makes the error disappear.

I believe we need to thread the custom action type through combineReducers to PreloadedStateShapeFromReducersMapObject so we can use it in the conditional type.

Steps to Reproduce

See above.

What is the expected behavior?

No type error.

Environment Details

N/A

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

Successfully merging a pull request may close this issue.

1 participant