#Typing actions's event parameter in v5

1 messages · Page 1 of 1 (latest)

north turret
#

In the machine in the example (parts removed for simplicity), in the definition of updateRecentSongs, "event" is inferred as { type: 'init' } | { type: 'play' }. The event however in this case comes from a promise actor and would have an output field with type Song[]. How can I make that available in the action (for narrowing)? Would adding an event of type done.invoke.app.loading:invocation[0] to the schema be the best way?

peak temple
#

Wow I have exactly the same question!

On a similar topic I was wondering if in v5 is best to use the onDone and onError with invoke with a promise ( to fetch data ), or if the callback with explicit separate states and events is still "slighlty more" recommended and easier to strongly type.

barren sedge
#

same Question

barren sedge
#

ok, when the action is inline works fine,
actions: [ ({event}) => console.log(event.output), {
the output in that case is typed correctly.

barren sedge
#

not sure if this is the right approach but I defined the action like this in order to have it strongly typed

peak temple
peak temple
obsidian oracle
#

Done events are something we still have to add to the types