Should effects types in @xstate/store better support async functions as arguments?
#5377
-
|
Hi there! 👋 This code pattern is quite common in my application now: const store = createStore(
{
context: {...},
on: {
requestReset: (ctx, _, enqueue) => {
enqueue.effect(async () => {
const result = await resetPassword(ctx.username);
result === true ? store.trigger.resetRequestSucceeded() : store.trigger.resetRequestError(result);
})
return { ...ctx, resetInFlight: true }
}
}
}
)We recently added typescript-eslint to help us increase the codebase quality, and the kind of code above violates the no-misused-promises rule: the function The workarounds are simple enough, but they're quite unappealing. Therefore, my question: Should effects types in @xstate/store better support Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
|
I think they can/should, but they'd be typed as |
Beta Was this translation helpful? Give feedback.
-
|
Wouldn't it be enough for you to configure the lint rule with |
Beta Was this translation helpful? Give feedback.
when you read code like:
you might think that we actually do something with this promise, handle errors, or await its result. But that's not true. For the same reason, you can't directly use async functions together with
React.useEffect: TS playgroundIt somewhat feels to me that you want this patch to trick the lint rule it's OK. But that lint rule exists exactly to guard you from misusing async functions in situations like this.