0

I am using XState and I need to pass a parameter via an Event.

export type InitializationEvent =
  | { type: 'FETCHED', name: string }
  | { type: 'ERROR', name: string }
  | { type: 'RESTART', name: string }

This is a method where I want to use the name property:

someAction: (context, event: InitializationEvent) => {
   doSomething(event.name);
},

Idea shows the event type is:

Alias for: InitEvent | {type: 'FETCHED', name: string} | {type: 'ERROR', name: string} | {type: 'RESTART', name: string}

InitEvent comes from the XState as:

export declare type InitEvent = { type: 'xstate.init'; }

But the build fails with:

TS2339: Property 'name' does not exist on type 'InitializationEvent'.
Property 'name' does not exist on type 'InitEvent'.

How can I properly access it? The method parameter event is cast to InitializationEvent so it should work, no?

Leos Literak
  • 8,805
  • 19
  • 81
  • 156

0 Answers0