Skip to content

Commit bb44754

Browse files
committed
Fix ComfyExtension types
1 parent 06a05cb commit bb44754

File tree

6 files changed

+29
-23
lines changed

6 files changed

+29
-23
lines changed

src/extensions/core/clipspace.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export class ClipspaceDialog extends ComfyDialog {
170170
app.registerExtension({
171171
name: 'Comfy.Clipspace',
172172
init(app) {
173+
// @ts-expect-error Move to ComfyApp
173174
app.openClipspace = function () {
174175
if (!ClipspaceDialog.instance) {
175176
ClipspaceDialog.instance = new ClipspaceDialog()

src/extensions/core/rerouteNode.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ app.registerExtension({
7474
const link = app.graph.links[linkId]
7575
if (!link) return
7676
const node = app.graph.getNodeById(link.origin_id)
77+
// @ts-expect-error Nodes that extend LGraphNode will not have a static type property
7778
const type = node.constructor.type
7879
if (type === 'Reroute') {
7980
if (node === this) {
@@ -112,6 +113,7 @@ app.registerExtension({
112113
if (!link) continue
113114

114115
const node = app.graph.getNodeById(link.target_id)
116+
// @ts-expect-error Nodes that extend LGraphNode will not have a static type property
115117
const type = node.constructor.type
116118

117119
if (type === 'Reroute') {
@@ -164,6 +166,7 @@ app.registerExtension({
164166
for (const l of node.outputs[0].links || []) {
165167
const link = app.graph.links[l]
166168
if (link) {
169+
// @ts-expect-error Fix litegraph types
167170
link.color = color
168171

169172
if (app.configuringGraph) continue
@@ -177,6 +180,7 @@ app.registerExtension({
177180
}
178181
if (!targetWidget) {
179182
targetWidget = targetNode.widgets?.find(
183+
// @ts-expect-error fix widget types
180184
(w) => w.name === targetInput.widget.name
181185
)
182186
}
@@ -209,6 +213,7 @@ app.registerExtension({
209213
if (inputNode) {
210214
const link = app.graph.links[inputNode.inputs[0].link]
211215
if (link) {
216+
// @ts-expect-error Fix litegraph types
212217
link.color = color
213218
}
214219
}

src/extensions/core/slotDefaults.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ app.registerExtension({
3030
slot_types_default_in: {},
3131
async beforeRegisterNodeDef(nodeType, nodeData, app) {
3232
var nodeId = nodeData.name
33-
var inputs = []
34-
inputs = nodeData['input']['required'] //only show required inputs to reduce the mess also not logical to create node with optional inputs
33+
const inputs = nodeData['input']['required'] //only show required inputs to reduce the mess also not logical to create node with optional inputs
3534
for (const inputKey in inputs) {
3635
var input = inputs[inputKey]
3736
if (typeof input[0] !== 'string') continue

src/extensions/core/widgetInputs.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,7 @@ app.registerExtension({
826826
}
827827

828828
function isNodeAtPos(pos) {
829+
// @ts-expect-error Fix litegraph types
829830
for (const n of app.graph._nodes) {
830831
if (n.pos[0] === pos[0] && n.pos[1] === pos[1]) {
831832
return true

src/scripts/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2871,7 +2871,7 @@ export class ComfyApp {
28712871
* Registers a Comfy web extension with the app
28722872
* @param {ComfyExtension} extension
28732873
*/
2874-
registerExtension(extension) {
2874+
registerExtension(extension: ComfyExtension) {
28752875
if (!extension.name) {
28762876
throw new Error("Extensions must have a 'name' property.")
28772877
}

src/types/comfy.d.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ import { LGraphNode, IWidget } from './litegraph'
22
import { ComfyApp } from '../scripts/app'
33
import type { ComfyNodeDef } from '@/types/apiTypes'
44

5+
export type Widgets = Record<
6+
string,
7+
(
8+
node,
9+
inputName,
10+
inputData,
11+
app?: ComfyApp
12+
) => { widget?: IWidget; minWidth?: number; minHeight?: number }
13+
>
14+
515
export interface ComfyExtension {
616
/**
717
* The name of the extension
@@ -11,12 +21,12 @@ export interface ComfyExtension {
1121
* Allows any initialisation, e.g. loading resources. Called after the canvas is created but before nodes are added
1222
* @param app The ComfyUI app instance
1323
*/
14-
init?(app: ComfyApp): Promise<void>
24+
init?(app: ComfyApp): Promise<void> | void
1525
/**
1626
* Allows any additional setup, called after the application is fully set up and running
1727
* @param app The ComfyUI app instance
1828
*/
19-
setup?(app: ComfyApp): Promise<void>
29+
setup?(app: ComfyApp): Promise<void> | void
2030
/**
2131
* Called before nodes are registered with the graph
2232
* @param defs The collection of node definitions, add custom ones or edit existing ones
@@ -25,25 +35,13 @@ export interface ComfyExtension {
2535
addCustomNodeDefs?(
2636
defs: Record<string, ComfyObjectInfo>,
2737
app: ComfyApp
28-
): Promise<void>
38+
): Promise<void> | void
2939
/**
3040
* Allows the extension to add custom widgets
3141
* @param app The ComfyUI app instance
3242
* @returns An array of {[widget name]: widget data}
3343
*/
34-
getCustomWidgets?(
35-
app: ComfyApp
36-
): Promise<
37-
Record<
38-
string,
39-
(
40-
node,
41-
inputName,
42-
inputData,
43-
app
44-
) => { widget?: IWidget; minWidth?: number; minHeight?: number }
45-
>
46-
>
44+
getCustomWidgets?(app: ComfyApp): Promise<Widgets> | Widgets
4745
/**
4846
* Allows the extension to add additional handling to the node before it is registered with **LGraph**
4947
* @param nodeType The node class (not an instance)
@@ -54,7 +52,7 @@ export interface ComfyExtension {
5452
nodeType: typeof LGraphNode,
5553
nodeData: ComfyObjectInfo,
5654
app: ComfyApp
57-
): Promise<void>
55+
): Promise<void> | void
5856

5957
/**
6058
* Allows the extension to modify the node definitions before they are used in the Vue app
@@ -71,21 +69,23 @@ export interface ComfyExtension {
7169
*
7270
* @param app The ComfyUI app instance
7371
*/
74-
registerCustomNodes?(app: ComfyApp): Promise<void>
72+
registerCustomNodes?(app: ComfyApp): Promise<void> | void
7573
/**
7674
* Allows the extension to modify a node that has been reloaded onto the graph.
7775
* If you break something in the backend and want to patch workflows in the frontend
7876
* This is the place to do this
7977
* @param node The node that has been loaded
8078
* @param app The ComfyUI app instance
8179
*/
82-
loadedGraphNode?(node: LGraphNode, app: ComfyApp)
80+
loadedGraphNode?(node: LGraphNode, app: ComfyApp): void
8381
/**
8482
* Allows the extension to run code after the constructor of the node
8583
* @param node The node that has been created
8684
* @param app The ComfyUI app instance
8785
*/
88-
nodeCreated?(node: LGraphNode, app: ComfyApp)
86+
nodeCreated?(node: LGraphNode, app: ComfyApp): void
87+
88+
[key: string]: any
8989
}
9090

9191
export type ComfyObjectInfo = {

0 commit comments

Comments
 (0)