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

3.4 regression when using Redux nested combineReducers #30685

Closed
OliverJAsh opened this issue Apr 1, 2019 · 2 comments
Closed

3.4 regression when using Redux nested combineReducers #30685

OliverJAsh opened this issue Apr 1, 2019 · 2 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@OliverJAsh
Copy link
Contributor

TypeScript Version: 3.4.1

Search Terms:

Code

//
// Redux types
//

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

type Reducer<S> = (state: S) => S;
declare function combineReducers<S>(reducers: { [K in keyof S]: Reducer<S[K]> }): Reducer<S>;

//
// Begin example
//

type MyState = { combined: { foo: number } };
declare const foo: Reducer<MyState['combined']['foo']>;

// When `strictFunctionTypes` is disabled…

{
    // Unexpected type error:
    // Property 'foo' is missing in type '{}' but required in type '{ foo: number; }'.
    const myReducer: Reducer<MyState> = combineReducers({
        combined: combineReducers({ foo }),
    });
}

{
    // Expected type: Reducer<{ combined: {}; }, AnyAction>
    // Actual type: Reducer<MyState, AnyAction>
    const myReducer = combineReducers({
        combined: combineReducers({ foo }),
    });
}

//
// Workaround:
//

{
    const combined = combineReducers({ foo });
    // No type error
    const myReducer: Reducer<MyState> = combineReducers({
        combined,
    });
}

{
    const combined = combineReducers({ foo });
    // Correct type inference
    const myReducer = combineReducers({
        combined,
    });
}
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Apr 9, 2019
@RyanCavanaugh
Copy link
Member

@ahejlsberg my read on this is that the contextual type inference candidate from the outer call is incorrectly causing {} inference of the inner call. Thoughts?

@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Apr 11, 2019
@ahejlsberg
Copy link
Member

The issue here is that we need a proper nonInferrableType that propagates in the same manner as anyFunctionType.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants