Skip to content
Merged
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
[fix] Add type guard for SubgraphDefinition to improve TypeScript inf…
…erence

The z.lazy() wrapper in the subgraph schema breaks TypeScript's type inference,
requiring developers to use 'as any[]' when accessing subgraph properties.

This commit adds:
- SubgraphDefinition type export
- isSubgraphDefinition() type guard function

This provides a type-safe alternative to 'as any[]' casting when working
with subgraphs in the codebase.

Related to #4650
  • Loading branch information
christian-byrne committed Aug 1, 2025
commit bcf940084997bb74d9b25f7fe6b075ee152acb30
18 changes: 18 additions & 0 deletions src/schemas/comfyWorkflowSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,24 @@ export type WorkflowJSON10 = z.infer<typeof zComfyWorkflow1>
export type ComfyWorkflowJSON = z.infer<
typeof zComfyWorkflow | typeof zComfyWorkflow1
>
export type SubgraphDefinition = z.infer<typeof zSubgraphDefinition>

/**
* Type guard to check if an object is a SubgraphDefinition.
* This helps TypeScript understand the type when z.lazy() breaks inference.
*/
export function isSubgraphDefinition(obj: any): obj is SubgraphDefinition {
return (
obj &&
typeof obj === 'object' &&
'id' in obj &&
'name' in obj &&
'nodes' in obj &&
Array.isArray(obj.nodes) &&
'inputNode' in obj &&
'outputNode' in obj
)
}

const zWorkflowVersion = z.object({
version: z.number()
Expand Down