#How do I raise from within an invokable without a TS error?
1 messages · Page 1 of 1 (latest)
it's also not clear why the event is untyped on that guard
this makes me feel better about this not being a user error: https://github.com/statelyai/xstate/blob/xstate%405.0.0-beta.13/packages/core/test/behaviors.test.ts#L350-L351
Like this:
success: {
entry: raise(({ context }) => ({
type: 'socket.thing_found' as const,
message: context.count > 0,
})),
},
You have to add as const because TS is silly has a hard time inferring this otherwise
Thanks so much for the help, David. Is there a way to get event in that guard typed? Or is that something that's coming later with the improved v5 typescript gen?
Not yet but there's a PR for that: https://github.com/statelyai/xstate/pull/4036
However, it's best to assert that event anyway, because this event comes from an external service, and you can't always guarantee that the event is what you expect
E.g. if it came from an API call, how can you be certain that the API responded with the exact type?
it seems that i'd want to narrow in the guard, and depending on the validity of (target to success and perform some action with the data) or go to a failure target. so ideally i'd only have to narrow in the guard to get the raise, assign, or other actions to pick up on the event, but i don't think that's possible. and i may not be making sense
or do the validations in the fetch
or is there a way to transition in assign, if the assign encounters an error