Skip to content

Create a factory for actions using createAction not working #3361

Discussion options

You must be logged in to vote

T must be guaranteed to satisfy the constraint NotAllowedInPropsCheck. This type guard excludes objects with a type property, empty objects, and primitives.

I am not aware of a way to type this such that a generic declared in actionFactory is guaranteed to pass this check. It only works with concrete object types.

However, if you take in a "props config" as a parameter, then you could make a factory:

const FEATURE_STATE_NAME = 'Some Feature';

function actionFactory<D extends string, P extends object>(description: D, /* include this param 👉 */ config: ActionCreatorProps<P> & NotAllowedCheck<P>) {
  return createAction(`[${FEATURE_STATE_NAME}] ${description}`, config);
}

// 👇 then pass a …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ChakirMrabet
Comment options

Answer selected by ChakirMrabet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants