piotrwitek/typesafe-actions

Request: ability to restrict the types for meta #70

renchap posted onGitHub

I would like to have a strong typing for the meta attribute on my actions.

I tried to define my own action() method with stricter types:

import { action as originalAction } from "typesafe-actions"

export const action: (
  type: string,
  payload?: any,
  meta?: ActionMetaType,
) => PayloadMetaAction<string, any, ActionMetaType> = originalAction

If I do this, I am loosing the type on my AppAction union type, for example:

error TS2339: Property 'payload' does not exist on type 'AppAction'.
  Property 'payload' does not exist on type '{ type: string; meta: ActionMetaType; }'.

I am not sure what is the best way to achieve this, but it would be really awesome to be able to do it!


Fund this Issue

Rewarded pull request

Recent activities

piotrwitek was rewarded for piotrwitek/typesafe-actions# 70
almost 6 years ago
piotrwitek submitted an output to  piotrwitek/ typesafe-actions# 70
almost 6 years ago