Skip to content

Commit c82401c

Browse files
authored
[TS] Fix strict type on chain callback, widgetInput (#3727)
1 parent 2c75948 commit c82401c

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

src/composables/functional/useChainCallback.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/**
2+
* Shorthand for {@link Parameters} of optional callbacks.
3+
*
4+
* @example
5+
* ```ts
6+
* const { onClick } = CustomClass.prototype
7+
* CustomClass.prototype.onClick = function (...args: CallbackParams<typeof onClick>) {
8+
* const r = onClick?.apply(this, args)
9+
* // ...
10+
* return r
11+
* }
12+
* ```
13+
*/
14+
export type CallbackParams<T extends ((...args: any) => any) | undefined> =
15+
Parameters<Exclude<T, undefined>>
16+
117
/**
218
* Chain multiple callbacks together.
319
*
@@ -14,6 +30,6 @@ export const useChainCallback = <
1430
) => {
1531
return function (this: O, ...args: Parameters<T>) {
1632
originalCallback?.call(this, ...args)
17-
callbacks.forEach((callback) => callback.call(this, ...args))
33+
for (const callback of callbacks) callback.call(this, ...args)
1834
}
1935
}

src/extensions/core/widgetInputs.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import type {
99
} from '@comfyorg/litegraph'
1010
import type { CanvasMouseEvent } from '@comfyorg/litegraph/dist/types/events'
1111

12-
import { useChainCallback } from '@/composables/functional/useChainCallback'
12+
import {
13+
type CallbackParams,
14+
useChainCallback
15+
} from '@/composables/functional/useChainCallback'
1316
import type { InputSpec } from '@/schemas/nodeDefSchema'
1417
import { app } from '@/scripts/app'
1518
import { ComfyWidgets, addValueControlWidgets } from '@/scripts/widgets'
@@ -564,12 +567,9 @@ app.registerExtension({
564567
const origOnInputDblClick = nodeType.prototype.onInputDblClick
565568
nodeType.prototype.onInputDblClick = function (
566569
this: LGraphNode,
567-
slot: number
570+
...[slot, ...args]: CallbackParams<typeof origOnInputDblClick>
568571
) {
569-
const r = origOnInputDblClick
570-
? // @ts-expect-error fixme ts strict error
571-
origOnInputDblClick.apply(this, arguments)
572-
: undefined
572+
const r = origOnInputDblClick?.apply(this, [slot, ...args])
573573

574574
const input = this.inputs[slot]
575575
if (!input.widget) {

0 commit comments

Comments
 (0)