From 867ed4c1d73f94d247c7e5e45862751470c08ce6 Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Wed, 19 Mar 2025 20:58:13 -0400 Subject: [PATCH] [Schema] Update zod schema on zVector2 (#3152) --- src/schemas/comfyWorkflowSchema.ts | 2 +- src/scripts/api.ts | 2 +- src/scripts/app.ts | 6 ++---- src/scripts/changeTracker.ts | 3 ++- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/schemas/comfyWorkflowSchema.ts b/src/schemas/comfyWorkflowSchema.ts index 800453b252..1b9e0766b8 100644 --- a/src/schemas/comfyWorkflowSchema.ts +++ b/src/schemas/comfyWorkflowSchema.ts @@ -26,7 +26,7 @@ const zVector2 = z.union([ z .object({ 0: z.number(), 1: z.number() }) .passthrough() - .transform((v) => [v[0], v[1]]), + .transform((v) => [v[0], v[1]] as [number, number]), z.tuple([z.number(), z.number()]) ]) diff --git a/src/scripts/api.ts b/src/scripts/api.ts index 655974afb7..548d98d459 100644 --- a/src/scripts/api.ts +++ b/src/scripts/api.ts @@ -130,7 +130,7 @@ type SimpleApiEvents = keyof PickNevers /** Keys (names) of API events that pass a {@link CustomEvent} `detail` object. */ type ComplexApiEvents = keyof NeverNever -/** EventTarget typing has no generic capability. This interface enables tsc strict. */ +/** EventTarget typing has no generic capability. */ export interface ComfyApi extends EventTarget { addEventListener( type: TEvent, diff --git a/src/scripts/app.ts b/src/scripts/app.ts index 2e6dcec3ed..96d325ae65 100644 --- a/src/scripts/app.ts +++ b/src/scripts/app.ts @@ -1129,9 +1129,6 @@ export class ComfyApp { useSettingStore().get('Comfy.EnableWorkflowViewRestore') && graphData.extra?.ds ) { - // @ts-expect-error - // Need to set strict: true for zod to match the type [number, number] - // https://github.com/colinhacks/zod/issues/3056 this.canvas.ds.offset = graphData.extra.ds.offset this.canvas.ds.scale = graphData.extra.ds.scale } @@ -1616,7 +1613,8 @@ export class ComfyApp { app.graph.arrange() - // @ts-expect-error zod type issue on ComfyWorkflowJSON. Should be resolved after enabling ts-strict globally. + // @ts-expect-error zod type issue on ComfyWorkflowJSON. ComfyWorkflowJSON + // is stricter than LiteGraph's serialisation schema. useWorkflowService().afterLoadNewGraph(fileName, this.serializeGraph()) } diff --git a/src/scripts/changeTracker.ts b/src/scripts/changeTracker.ts index 6f3e44492b..0916bcf8b5 100644 --- a/src/scripts/changeTracker.ts +++ b/src/scripts/changeTracker.ts @@ -107,7 +107,8 @@ export class ChangeTracker { checkState() { if (!this.app.graph || this.changeCount) return - // @ts-expect-error zod types issue. Will be fixed after we enable ts-strict + // @ts-expect-error zod type issue on ComfyWorkflowJSON. ComfyWorkflowJSON + // is stricter than LiteGraph's serialisation schema. const currentState = clone(this.app.graph.serialize()) as ComfyWorkflowJSON if (!this.activeState) { this.activeState = currentState