Enforce ComfyExtension types (#1718)

* Enforce extension types

* nit
This commit is contained in:
Chenlei Hu
2024-11-27 12:35:18 -08:00
committed by GitHub
parent 39eaa2e850
commit c4d3c672ad
7 changed files with 27 additions and 4 deletions

View File

@@ -724,6 +724,7 @@ app.registerExtension({
async beforeRegisterNodeDef(nodeType, nodeData, app) {
// Add menu options to convert to/from widgets
const origGetExtraMenuOptions = nodeType.prototype.getExtraMenuOptions
// @ts-expect-error adding extra property
nodeType.prototype.convertWidgetToInput = function (widget) {
const config = getConfig.call(this, widget.name) ?? [
widget.type,
@@ -746,8 +747,10 @@ app.registerExtension({
if (w.options?.forceInput) {
continue
}
// @ts-expect-error custom widget type
if (w.type === CONVERTED_TYPE) {
toWidget.push({
// @ts-expect-error never
content: `Convert ${w.name} to widget`,
callback: () => convertToWidget(this, w)
})
@@ -860,7 +863,9 @@ app.registerExtension({
for (const input of this.inputs) {
if (input.widget && !input.widget[GET_CONFIG]) {
input.widget[GET_CONFIG] = () =>
// @ts-expect-error input.widget has unknown type
getConfig.call(this, input.widget.name)
// @ts-expect-error input.widget has unknown type
const w = this.widgets.find((w) => w.name === input.widget.name)
if (w) {
hideWidget(this, w)
@@ -935,6 +940,7 @@ app.registerExtension({
originNode,
originSlot
) {
// @ts-expect-error onConnectInput has 5 arguments
const v = onConnectInput?.(this, arguments)
// Not a combo, ignore
if (type !== 'COMBO') return v