microsoft / redux-dynamic-modules

Modularize Redux by dynamically loading reducers and middlewares.
https://redux-dynamic-modules.js.org
MIT License
1.07k stars 116 forks source link

Typescript action in Saga watcher #124

Closed jacksontong closed 4 years ago

jacksontong commented 4 years ago

I'm using ActionHelper.ts from the typescript example to create my action and I don't know how to typing the action in my saga watcher

// action.ts
import { createAction, ActionsUnion } from "ActionHelper"

export enum ActionTypes {
  REQUEST_DELETE  = "REQUEST_DELETE",
}

export const Actions = {
  requestDelete: (id: number) => createAction(ActionTypes.REQUEST_DELETE, { id }),
}

export type ActionsUnion = ActionsUnion<typeof Actions>

// saga.ts
function* handleRequestDelete(action: any) {
  const id = action.payload.id

}
jacksontong commented 4 years ago

I'm able to solve this by ReturnType

// saga.ts
function* handleRequestDelete(action: ReturnType<typeof Actions.requestDelete>) {
  const id = action.payload.id

}