-
Notifications
You must be signed in to change notification settings - Fork 13.3k
3.4 regression when using Redux nested combineReducers #30685
Copy link
Copy link
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
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,
});
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue