From 61c9341450f56f892cc7673b33de8a1fb799df3e Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Fri, 1 Aug 2025 17:37:06 -0700 Subject: [PATCH] [fix] Add type guard for SubgraphDefinition to improve TypeScript inference (#4651) --- src/schemas/comfyWorkflowSchema.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/schemas/comfyWorkflowSchema.ts b/src/schemas/comfyWorkflowSchema.ts index 23dd04d01..70ebcd279 100644 --- a/src/schemas/comfyWorkflowSchema.ts +++ b/src/schemas/comfyWorkflowSchema.ts @@ -458,6 +458,24 @@ export type WorkflowJSON10 = z.infer export type ComfyWorkflowJSON = z.infer< typeof zComfyWorkflow | typeof zComfyWorkflow1 > +export type SubgraphDefinition = z.infer + +/** + * 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()