Skip to content

Misleading parameter name in ThunkDispatch type #215

@jmrog

Description

@jmrog

The current types for ThunkDispatch and ThunkAction look like this:

export interface ThunkDispatch<S, E, A extends Action> {
  <T extends A>(action: T): T;
  <R>(asyncAction: ThunkAction<R, S, E, A>): R;
}

export type ThunkAction<R, S, E, A extends Action> = (
  dispatch: ThunkDispatch<S, E, A>,
  getState: () => S,
  extraArgument: E
) => R;

In the second overload of ThunkDispatch, the parameter is named asyncAction. In my opinion, this name is misleading, because ThunkAction does not have to be asynchronous. Using thunk for asynchronous actions is something you can do, but it also has some synchronous use cases -- e.g., as the README itself notes (emphases added), "The thunk can be used to delay the dispatch of an action, or to dispatch [even synchronously!] only if a certain condition is met." So, I'd like to recommend changing the name to just "thunkAction" (PR incoming!), in the hopes that will prevent some potential confusion.

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