Skip to content

Instantly share code, notes, and snippets.

@flushentitypacket
Created January 20, 2018 19:33
Show Gist options
  • Save flushentitypacket/9775421e4c69752fa5a20e92cec8edf6 to your computer and use it in GitHub Desktop.
Save flushentitypacket/9775421e4c69752fa5a20e92cec8edf6 to your computer and use it in GitHub Desktop.
Typescript Redux generic Action
// store/redux.d.ts
import {Action as ReduxAction} from 'redux'
export interface Action<
T extends string,
P = undefined
> extends ReduxAction {
type: T
payload: P
}
// example use
const TOGGLE = 'toggle'
interface ActionToggle extends Action<typeof TOGGLE> {}
const ADD = 'add'
interface ActionAdd extends Action<typeof ADD, number> {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment