[Type] Disallow type upcasting for node input spec (#2790)

This commit is contained in:
Chenlei Hu
2025-03-01 16:58:45 -05:00
committed by GitHub
parent bca0af82a3
commit 09ab14ac81
20 changed files with 136 additions and 109 deletions

View File

@@ -17,6 +17,7 @@ export const useBooleanWidget = () => {
}
return {
// @ts-expect-error InputSpec is not typed correctly
widget: node.addWidget('toggle', inputName, defaultVal, () => {}, options)
}
}

View File

@@ -20,6 +20,7 @@ export const useComboWidget = () => {
const res = {
widget: node.addWidget('combo', inputName, defaultValue, () => {}, {
// @ts-expect-error InputSpec is not typed correctly
values: options ?? inputData[0]
}) as IComboWidget
}
@@ -31,6 +32,7 @@ export const useComboWidget = () => {
node,
widget: res.widget
})
// @ts-expect-error InputSpec is not typed correctly
if (remote.refresh_button) remoteWidget.addRefreshButton()
const origOptions = res.widget.options

View File

@@ -2,7 +2,7 @@ import type { LGraphNode } from '@comfyorg/litegraph'
import type { INumericWidget } from '@comfyorg/litegraph/dist/types/widgets'
import _ from 'lodash'
import type { InputSpec } from '@/schemas/nodeDefSchema'
import type { FloatInputOptions, InputSpec } from '@/schemas/nodeDefSchema'
import type { ComfyWidgetConstructor } from '@/scripts/widgets'
import { useSettingStore } from '@/stores/settingStore'
import { getNumberDefaults } from '@/utils/mathUtil'
@@ -45,11 +45,14 @@ export const useFloatWidget = () => {
settingStore.get('Comfy.FloatRoundingPrecision') || undefined
const enableRounding = !settingStore.get('Comfy.DisableFloatRounding')
const { val, config } = getNumberDefaults(inputOptions, {
defaultStep: 0.5,
precision,
enableRounding
})
const { val, config } = getNumberDefaults(
inputOptions as FloatInputOptions,
{
defaultStep: 0.5,
precision,
enableRounding
}
)
return {
widget: node.addWidget(
@@ -57,6 +60,7 @@ export const useFloatWidget = () => {
inputName,
val,
onFloatValueChange,
// @ts-expect-error InputSpec is not typed correctly
config
)
}

View File

@@ -44,9 +44,11 @@ export const useImageUploadWidget = () => {
const { showPreview } = isVideo ? useNodeVideo(node) : useNodeImage(node)
const fileFilter = isVideo ? isVideoFile : isImageFile
// @ts-expect-error InputSpec is not typed correctly
const fileComboWidget = findFileComboWidget(node, imageInputName)
const initialFile = `${fileComboWidget.value}`
const formatPath = (value: InternalFile) =>
// @ts-expect-error InputSpec is not typed correctly
createAnnotatedPath(value, { rootFolder: image_folder })
const transform = (internalValue: InternalValue): ExposedValue => {
@@ -66,6 +68,7 @@ export const useImageUploadWidget = () => {
// Setup file upload handling
const { openFileSelection } = useNodeImageUpload(node, {
// @ts-expect-error InputSpec is not typed correctly
allow_batch,
fileFilter,
accept,

View File

@@ -1,7 +1,7 @@
import type { LGraphNode } from '@comfyorg/litegraph'
import type { INumericWidget } from '@comfyorg/litegraph/dist/types/widgets'
import type { InputSpec } from '@/schemas/nodeDefSchema'
import type { InputSpec, IntInputOptions } from '@/schemas/nodeDefSchema'
import type { ComfyApp } from '@/scripts/app'
import {
type ComfyWidgetConstructor,
@@ -50,7 +50,7 @@ export const useIntWidget = () => {
: 'number'
: 'number'
const { val, config } = getNumberDefaults(inputOptions, {
const { val, config } = getNumberDefaults(inputOptions as IntInputOptions, {
defaultStep: 1,
precision: 0,
enableRounding: true
@@ -58,6 +58,7 @@ export const useIntWidget = () => {
config.precision = 0
const result = {
// @ts-expect-error InputSpec is not typed correctly
widget: node.addWidget(widgetType, inputName, val, onValueChange, config)
}

View File

@@ -73,7 +73,7 @@ export function useRemoteWidget<
widget: IWidget
}) {
const { inputData, defaultValue, node, widget } = options
const config: RemoteWidgetConfig = inputData[1].remote
const config = (inputData[1]?.remote ?? {}) as RemoteWidgetConfig
const { refresh = 0, max_retries = MAX_RETRIES } = config
const isPermanent = refresh <= 0
const cacheKey = createCacheKey(config)

View File

@@ -82,6 +82,7 @@ export const useStringWidget = () => {
}
if (inputData[1]?.dynamicPrompts != undefined)
// @ts-expect-error InputSpec is not typed correctly
res.widget.dynamicPrompts = inputData[1].dynamicPrompts
return res