Skip to content

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

@OliverJAsh

Description

@OliverJAsh

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

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