From 38291bee5165d4f480f2bfc93fad55bf998fbf96 Mon Sep 17 00:00:00 2001 From: snomiao Date: Tue, 16 Sep 2025 13:44:50 +0000 Subject: [PATCH] [fix] Remove TypeScript declare modifiers from class properties --- scripts/collect-i18n-node-defs.ts | 2 +- src/lib/litegraph/src/LGraphNode.ts | 4 ++-- src/lib/litegraph/src/canvas/FloatingRenderLink.ts | 10 ++++++++-- .../litegraph/src/subgraph/EmptySubgraphInput.ts | 4 +--- .../litegraph/src/subgraph/EmptySubgraphOutput.ts | 4 +--- src/lib/litegraph/src/subgraph/SubgraphInput.ts | 14 ++++++-------- src/lib/litegraph/src/subgraph/SubgraphNode.ts | 3 ++- src/lib/litegraph/src/subgraph/SubgraphOutput.ts | 12 +++++------- src/lib/litegraph/src/widgets/BaseWidget.ts | 4 ++-- .../core/__snapshots__/LGraph.test.ts.snap | 6 ++++++ 10 files changed, 34 insertions(+), 29 deletions(-) diff --git a/scripts/collect-i18n-node-defs.ts b/scripts/collect-i18n-node-defs.ts index ed443015a..11abd660f 100644 --- a/scripts/collect-i18n-node-defs.ts +++ b/scripts/collect-i18n-node-defs.ts @@ -11,7 +11,7 @@ const nodeDefsPath = './src/locales/en/nodeDefs.json' test('collect-i18n-node-defs', async ({ comfyPage }) => { // Mock view route - comfyPage.page.route('**/view**', async (route) => { + await comfyPage.page.route('**/view**', async (route) => { await route.fulfill({ body: JSON.stringify({}) }) diff --git a/src/lib/litegraph/src/LGraphNode.ts b/src/lib/litegraph/src/LGraphNode.ts index 20e26e211..4f300e0f7 100644 --- a/src/lib/litegraph/src/LGraphNode.ts +++ b/src/lib/litegraph/src/LGraphNode.ts @@ -404,8 +404,8 @@ export class LGraphNode selected?: boolean showAdvanced?: boolean - declare comfyClass?: string - declare isVirtualNode?: boolean + comfyClass?: string + isVirtualNode?: boolean applyToGraph?(extraLinks?: LLink[]): void isSubgraphNode(): this is SubgraphNode { diff --git a/src/lib/litegraph/src/canvas/FloatingRenderLink.ts b/src/lib/litegraph/src/canvas/FloatingRenderLink.ts index 7bb61bd82..e4bc66b4e 100644 --- a/src/lib/litegraph/src/canvas/FloatingRenderLink.ts +++ b/src/lib/litegraph/src/canvas/FloatingRenderLink.ts @@ -14,7 +14,9 @@ import type { import type { INodeInputSlot } from '@/lib/litegraph/src/interfaces' import type { Point } from '@/lib/litegraph/src/interfaces' import type { SubgraphInput } from '@/lib/litegraph/src/subgraph/SubgraphInput' +import type { SubgraphInputNode } from '@/lib/litegraph/src/subgraph/SubgraphInputNode' import type { SubgraphOutput } from '@/lib/litegraph/src/subgraph/SubgraphOutput' +import type { SubgraphOutputNode } from '@/lib/litegraph/src/subgraph/SubgraphOutputNode' import { LinkDirection } from '@/lib/litegraph/src/types/globalEnums' import type { RenderLink } from './RenderLink' @@ -175,7 +177,9 @@ export class FloatingRenderLink implements RenderLink { ): void { const floatingLink = this.link floatingLink.origin_id = SUBGRAPH_INPUT_ID - floatingLink.origin_slot = input.parent.slots.indexOf(input) + floatingLink.origin_slot = ( + input.parent as SubgraphInputNode + ).slots.indexOf(input) this.fromSlot._floatingLinks?.delete(floatingLink) input._floatingLinks ??= new Set() @@ -188,7 +192,9 @@ export class FloatingRenderLink implements RenderLink { ): void { const floatingLink = this.link floatingLink.origin_id = SUBGRAPH_OUTPUT_ID - floatingLink.origin_slot = output.parent.slots.indexOf(output) + floatingLink.origin_slot = ( + output.parent as SubgraphOutputNode + ).slots.indexOf(output) this.fromSlot._floatingLinks?.delete(floatingLink) output._floatingLinks ??= new Set() diff --git a/src/lib/litegraph/src/subgraph/EmptySubgraphInput.ts b/src/lib/litegraph/src/subgraph/EmptySubgraphInput.ts index 0419b18d3..fe66c9543 100644 --- a/src/lib/litegraph/src/subgraph/EmptySubgraphInput.ts +++ b/src/lib/litegraph/src/subgraph/EmptySubgraphInput.ts @@ -12,8 +12,6 @@ import type { SubgraphInputNode } from './SubgraphInputNode' * A virtual slot that simply creates a new input slot when connected to. */ export class EmptySubgraphInput extends SubgraphInput { - declare parent: SubgraphInputNode - constructor(parent: SubgraphInputNode) { super( { @@ -30,7 +28,7 @@ export class EmptySubgraphInput extends SubgraphInput { node: LGraphNode, afterRerouteId?: RerouteId ): LLink | undefined { - const { subgraph } = this.parent + const { subgraph } = this.parent as SubgraphInputNode const existingNames = subgraph.inputs.map((x) => x.name) const name = nextUniqueName(slot.name, existingNames) diff --git a/src/lib/litegraph/src/subgraph/EmptySubgraphOutput.ts b/src/lib/litegraph/src/subgraph/EmptySubgraphOutput.ts index afb52b120..5c3ad1e6c 100644 --- a/src/lib/litegraph/src/subgraph/EmptySubgraphOutput.ts +++ b/src/lib/litegraph/src/subgraph/EmptySubgraphOutput.ts @@ -12,8 +12,6 @@ import type { SubgraphOutputNode } from './SubgraphOutputNode' * A virtual slot that simply creates a new output slot when connected to. */ export class EmptySubgraphOutput extends SubgraphOutput { - declare parent: SubgraphOutputNode - constructor(parent: SubgraphOutputNode) { super( { @@ -30,7 +28,7 @@ export class EmptySubgraphOutput extends SubgraphOutput { node: LGraphNode, afterRerouteId?: RerouteId ): LLink | undefined { - const { subgraph } = this.parent + const { subgraph } = this.parent as SubgraphOutputNode const existingNames = subgraph.outputs.map((x) => x.name) const name = nextUniqueName(slot.name, existingNames) diff --git a/src/lib/litegraph/src/subgraph/SubgraphInput.ts b/src/lib/litegraph/src/subgraph/SubgraphInput.ts index 63465d2b5..188af5549 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphInput.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphInput.ts @@ -30,8 +30,6 @@ import { isNodeSlot, isSubgraphOutput } from './subgraphUtils' * Functionally, however, when editing a subgraph, that "subgraph input" is the "origin" or "output side" of a link. */ export class SubgraphInput extends SubgraphSlot { - declare parent: SubgraphInputNode - events = new CustomEventTarget() /** The linked widget that this slot is connected to. */ @@ -50,13 +48,13 @@ export class SubgraphInput extends SubgraphSlot { node: LGraphNode, afterRerouteId?: RerouteId ): LLink | undefined { - const { subgraph } = this.parent + const parent = this.parent as SubgraphInputNode + const { subgraph } = parent // Allow nodes to block connection const inputIndex = node.inputs.indexOf(slot) if ( - node.onConnectInput?.(inputIndex, this.type, this, this.parent, -1) === - false + node.onConnectInput?.(inputIndex, this.type, this, parent, -1) === false ) return @@ -77,7 +75,7 @@ export class SubgraphInput extends SubgraphSlot { if (slot.link != null) { subgraph.beforeChange() const link = subgraph.getLink(slot.link) - this.parent._disconnectNodeInput(node, slot, link) + parent._disconnectNodeInput(node, slot, link) } const inputWidget = node.getWidgetFromSlot(slot) @@ -97,8 +95,8 @@ export class SubgraphInput extends SubgraphSlot { const link = new LLink( ++subgraph.state.lastLinkId, slot.type, - this.parent.id, - this.parent.slots.indexOf(this), + parent.id, + parent.slots.indexOf(this), node.id, inputIndex, afterRerouteId diff --git a/src/lib/litegraph/src/subgraph/SubgraphNode.ts b/src/lib/litegraph/src/subgraph/SubgraphNode.ts index dc47f477e..ad7727b27 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphNode.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphNode.ts @@ -35,7 +35,8 @@ import type { SubgraphInput } from './SubgraphInput' * An instance of a {@link Subgraph}, displayed as a node on the containing (parent) graph. */ export class SubgraphNode extends LGraphNode implements BaseLGraph { - declare inputs: (INodeInputSlot & Partial)[] + // Override inputs with proper typing for subgraph inputs + override inputs: (INodeInputSlot & Partial)[] = [] override readonly type: UUID override readonly isVirtualNode = true as const diff --git a/src/lib/litegraph/src/subgraph/SubgraphOutput.ts b/src/lib/litegraph/src/subgraph/SubgraphOutput.ts index 96901d423..2be2fdf06 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphOutput.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphOutput.ts @@ -29,14 +29,13 @@ import { isNodeSlot, isSubgraphInput } from './subgraphUtils' * Functionally, however, when editing a subgraph, that "subgraph output" is the "target" or "input side" of a link. */ export class SubgraphOutput extends SubgraphSlot { - declare parent: SubgraphOutputNode - override connect( slot: INodeOutputSlot, node: LGraphNode, afterRerouteId?: RerouteId ): LLink | undefined { - const { subgraph } = this.parent + const parent = this.parent as SubgraphOutputNode + const { subgraph } = parent // Validate type compatibility if (!LiteGraph.isValidConnection(slot.type, this.type)) return @@ -47,8 +46,7 @@ export class SubgraphOutput extends SubgraphSlot { throw new Error('Slot is not an output of the given node') if ( - node.onConnectOutput?.(outputIndex, this.type, this, this.parent, -1) === - false + node.onConnectOutput?.(outputIndex, this.type, this, parent, -1) === false ) return @@ -68,8 +66,8 @@ export class SubgraphOutput extends SubgraphSlot { slot.type, node.id, outputIndex, - this.parent.id, - this.parent.slots.indexOf(this), + parent.id, + parent.slots.indexOf(this), afterRerouteId ) diff --git a/src/lib/litegraph/src/widgets/BaseWidget.ts b/src/lib/litegraph/src/widgets/BaseWidget.ts index c09668d9e..444f7c800 100644 --- a/src/lib/litegraph/src/widgets/BaseWidget.ts +++ b/src/lib/litegraph/src/widgets/BaseWidget.ts @@ -47,8 +47,8 @@ export abstract class BaseWidget /** Minimum gap between label and value */ static labelValueGap = 5 - declare computedHeight?: number - declare serialize?: boolean + computedHeight?: number + serialize?: boolean computeLayoutSize?(node: LGraphNode): { minHeight: number maxHeight?: number diff --git a/tests-ui/tests/litegraph/core/__snapshots__/LGraph.test.ts.snap b/tests-ui/tests/litegraph/core/__snapshots__/LGraph.test.ts.snap index 1ce83fb46..fd8ea9498 100644 --- a/tests-ui/tests/litegraph/core/__snapshots__/LGraph.test.ts.snap +++ b/tests-ui/tests/litegraph/core/__snapshots__/LGraph.test.ts.snap @@ -66,6 +66,7 @@ LGraph { "clip_area": undefined, "clonable": undefined, "color": undefined, + "comfyClass": undefined, "console": undefined, "exec_version": undefined, "execute_triggered": undefined, @@ -77,6 +78,7 @@ LGraph { "id": 1, "ignore_remove": undefined, "inputs": [], + "isVirtualNode": undefined, "last_serialization": { "id": 1, }, @@ -138,6 +140,7 @@ LGraph { "clip_area": undefined, "clonable": undefined, "color": undefined, + "comfyClass": undefined, "console": undefined, "exec_version": undefined, "execute_triggered": undefined, @@ -149,6 +152,7 @@ LGraph { "id": 1, "ignore_remove": undefined, "inputs": [], + "isVirtualNode": undefined, "last_serialization": { "id": 1, }, @@ -211,6 +215,7 @@ LGraph { "clip_area": undefined, "clonable": undefined, "color": undefined, + "comfyClass": undefined, "console": undefined, "exec_version": undefined, "execute_triggered": undefined, @@ -222,6 +227,7 @@ LGraph { "id": 1, "ignore_remove": undefined, "inputs": [], + "isVirtualNode": undefined, "last_serialization": { "id": 1, },