Skip to content

Update configureStore to extract TS types from enhancers (including dispatch overrides) #2241

Closed
@VldMrgnn

Description

@VldMrgnn

What version of React, ReactDOM/React Native, Redux, and React Redux are you using?

  • React: "^18.0.0"
  • ReactDOM/React Native: "^18.0.0"
  • Redux: "^4.1.2"
  • React Redux: "^8.0.0-rc.1"

What is the current behavior?

the store:

...
const sagaMiddleware = createSagaMiddleware(process.env.NODE_ENV !== "production" ? { sagaMonitor: sagaMonitor } : {});
const middlewareSeriesTwo = [reduxClipboardCopy, sagaMiddleware];
//
export const store = configureStore({
	reducer: rootReducer,
	middleware: (getDefaultMiddleware) => getDefaultMiddleware({
		serializableCheck: {
			ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER, 'SERVICES2PDF']
		}
	}).concat(middlewareSeriesTwo),
	devTools: process.env.NODE_ENV !== "production",
	enhancers: (defaultEnhancers) => [reduxBatch, ...defaultEnhancers, reduxBatch]
});

on dispatching an array of actions, like:

dispatch([
someAction0(payload),
someAction1(payload) 
])

get type error :

Argument of type '({ payload: string; type: string; } | { payload: object; type: string; })[]' is not assignable to parameter of type 'AnyAction'.
  Property 'type' is missing in type '({ payload: string; type: string; } | { payload: object; type: string; })[]' but required in type 'AnyAction'.ts(2345)
[index.d.ts(19, 3): ]()'type' is declared here.

declaring

dispatch([
someAction0(payload),
someAction1(payload) 
] as any)

solves the problem but I think that is not what we want.

What is the expected behavior?

To infer the array of actions as in previous version.

Which browser and OS are affected by this issue?

Server running on Debian / Client Windows, Chrome

Did this work in previous versions of React Redux?

  • Yes

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