mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-21 07:14:11 +00:00
[TS] Fix strict type on chain callback, widgetInput (#3727)
This commit is contained in:
@@ -1,3 +1,19 @@
|
||||
/**
|
||||
* Shorthand for {@link Parameters} of optional callbacks.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const { onClick } = CustomClass.prototype
|
||||
* CustomClass.prototype.onClick = function (...args: CallbackParams<typeof onClick>) {
|
||||
* const r = onClick?.apply(this, args)
|
||||
* // ...
|
||||
* return r
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
export type CallbackParams<T extends ((...args: any) => any) | undefined> =
|
||||
Parameters<Exclude<T, undefined>>
|
||||
|
||||
/**
|
||||
* Chain multiple callbacks together.
|
||||
*
|
||||
@@ -14,6 +30,6 @@ export const useChainCallback = <
|
||||
) => {
|
||||
return function (this: O, ...args: Parameters<T>) {
|
||||
originalCallback?.call(this, ...args)
|
||||
callbacks.forEach((callback) => callback.call(this, ...args))
|
||||
for (const callback of callbacks) callback.call(this, ...args)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,10 @@ import type {
|
||||
} from '@comfyorg/litegraph'
|
||||
import type { CanvasMouseEvent } from '@comfyorg/litegraph/dist/types/events'
|
||||
|
||||
import { useChainCallback } from '@/composables/functional/useChainCallback'
|
||||
import {
|
||||
type CallbackParams,
|
||||
useChainCallback
|
||||
} from '@/composables/functional/useChainCallback'
|
||||
import type { InputSpec } from '@/schemas/nodeDefSchema'
|
||||
import { app } from '@/scripts/app'
|
||||
import { ComfyWidgets, addValueControlWidgets } from '@/scripts/widgets'
|
||||
@@ -564,12 +567,9 @@ app.registerExtension({
|
||||
const origOnInputDblClick = nodeType.prototype.onInputDblClick
|
||||
nodeType.prototype.onInputDblClick = function (
|
||||
this: LGraphNode,
|
||||
slot: number
|
||||
...[slot, ...args]: CallbackParams<typeof origOnInputDblClick>
|
||||
) {
|
||||
const r = origOnInputDblClick
|
||||
? // @ts-expect-error fixme ts strict error
|
||||
origOnInputDblClick.apply(this, arguments)
|
||||
: undefined
|
||||
const r = origOnInputDblClick?.apply(this, [slot, ...args])
|
||||
|
||||
const input = this.inputs[slot]
|
||||
if (!input.widget) {
|
||||
|
||||
Reference in New Issue
Block a user