createAction Function

Creates a basic Redux Redux Action without a payload. This is meant to be used as a shortcut for defining Action Creators.

For example,

  () => createAction("FOO", ids)

defines an action creator of type:

  () => { type: "FOO" }
  // which is equivalent to:
  () => Action<"FOO">

Note that the generic type parameters can always be omitted - TypeScript will be able to infer them.

createAction<T extends string>(type: T extends string): Action<T extends string>

Parameter Type Description
type T extends string The string to use as the action's type property. Should have a string literal type.

Creates a basic Redux Redux Action with a payload value. This is meant to be used as a shortcut for defining Action Creators.

For example,

  (ids: number[]) => createAction("FOO", ids)

defines an action creator of type:

  (ids: number[]) => { type: "FOO", payload: ReadonlyArray<number> }
  // which is equivalent to:
  (ids: number[]) => ActionWithPayload<"FOO", ReadonlyArray<number>>

Note that the generic type parameters can always be omitted - TypeScript will be able to infer them.

createAction<T extends string, P>(type: T extends string, payload: P): ActionWithPayload<T extends string, DeepReadonly<P>>

Parameter Type Description
type T extends string The string to use as the action's type property. Should have a string literal type.
payload P The value to use as the action's payload property. May be of any type.

Defined in

Last Updated: 20 September, 2019