Skip to content

Middleware action is typed as any #4518

@ethanneff

Description

@ethanneff

The documentation is missing typing on action. https://redux.js.org/usage/usage-with-typescript#type-checking-middleware

export type AppStore = typeof store;
export type AppState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;
export type AppMiddleware = Middleware<void, AppState, AppDispatch>;

export const loggerMiddleware: AppMiddleware =
  (storeApi) => (next) => (action) => {
    const state = storeApi.getState();

    console.log(action.type, state); // Unsafe member access .type on an `any` value.

    return next(action); // Unsafe return of an `any` typed value.
  };

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions