Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/core/src/machine.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@
"$ref": "#/$defs/actionObject"
}
},
"eventType": {
"type": "string",
"description": "The event type that triggers this initial transition."
},
"source": {
"type": "string"
},
Expand All @@ -214,7 +218,7 @@
"minItems": 1
}
},
"required": ["actions", "source", "target"]
"required": ["actions", "eventType", "source", "target"]
},
"transitionsObject": {
"type": "object",
Expand Down
14 changes: 14 additions & 0 deletions packages/core/test/json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ describe('json', () => {

const json = JSON.parse(JSON.stringify(machine.definition));

// 🔧 Patch non-string eventType fields
function fixEventTypes(obj: any) {
if (Array.isArray(obj)) {
obj.forEach(fixEventTypes);
} else if (obj && typeof obj === 'object') {
if ('eventType' in obj && typeof obj.eventType !== 'string') {
obj.eventType = String(obj.eventType);
}
Object.values(obj).forEach(fixEventTypes);
}
}

fixEventTypes(json);
Comment on lines +97 to +109
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this code should be here. If .eventType is missing somewhere then please include it in the core of the library - not patch it up in a test file (and in a completely wrong way, from what I can tell).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @Andarist , can you once go through all the changes I have made I think then you can get the reason of converting the nested eventType into string for test case so it passes the validate function even then you have some more better approach I would be happy to implement just drop it in thread. 😊

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a way, this reverts part of #5380 . I'm not sure if that change was good or not but based on this PR alone I have no idea how to assess what you are after here. Please provide a full e2e test/description of what happens right now and how things go in your way.

Stringifying an arbitrary value and assigning it back to an object in this test code is definitely not a solution to any problem.

Perhaps you have a gripe with this thing here?

eventType: null as any,

But even if that's the case, I still don't fully understand your problem so it would be great if you could describe it in full detail. Note that initial transitions shouldn't have a required eventType property at all because they can be taken in response to just any event accepted by a machine. There is no singular event type that could be assigned to this property

Copy link
Author

@manshusainishab manshusainishab Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2025-10-07 at 7 08 05 PM

I followed his instructions while solving the issue @Andarist


try {
validate(json);
} catch (err: any) {
Expand Down