Skip to content

Instantly share code, notes, and snippets.

@Haosvit
Created August 6, 2020 07:24
Show Gist options
  • Save Haosvit/410f76943bb022fcf228d20748e302ac to your computer and use it in GitHub Desktop.
Save Haosvit/410f76943bb022fcf228d20748e302ac to your computer and use it in GitHub Desktop.
import { ActionCreatorBuilder, getType } from 'typesafe-actions';
interface IAppAction {
type: string;
payload: any;
[extra: string]: any;
}
export function isType<TPayload = any>(
action: IAppAction,
actionCreator: ActionCreatorBuilder<string, TPayload, any>,
): action is ReturnType<typeof actionCreator> {
return (action as ReturnType<typeof actionCreator>).type === getType(actionCreator);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment