mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-11 10:30:10 +00:00
fix(services): remove @ts-expect-error suppressions with proper types
This commit is contained in:
@@ -201,9 +201,10 @@ export const useLitegraphService = () => {
|
||||
*/
|
||||
function addInputs(node: LGraphNode, inputs: Record<string, InputSpec>) {
|
||||
// Use input_order if available to ensure consistent widget ordering
|
||||
//@ts-expect-error was ComfyNode.nodeData as ComfyNodeDefImpl
|
||||
const nodeDefImpl = node.constructor.nodeData as ComfyNodeDefImpl
|
||||
const orderedInputSpecs = getOrderedInputSpecs(nodeDefImpl, inputs)
|
||||
const orderedInputSpecs = getOrderedInputSpecs(
|
||||
node.constructor.nodeData,
|
||||
inputs
|
||||
)
|
||||
|
||||
// Create sockets and widgets in the determined order
|
||||
for (const inputSpec of orderedInputSpecs) addInputSocket(node, inputSpec)
|
||||
@@ -512,8 +513,8 @@ export const useLitegraphService = () => {
|
||||
const url = new URL(img.src)
|
||||
url.searchParams.delete('preview')
|
||||
|
||||
// @ts-expect-error fixme ts strict error
|
||||
const writeImage = async (blob) => {
|
||||
const writeImage = async (blob: Blob | null) => {
|
||||
if (!blob) return
|
||||
await navigator.clipboard.write([
|
||||
new ClipboardItem({
|
||||
[blob.type]: blob
|
||||
@@ -534,32 +535,28 @@ export const useLitegraphService = () => {
|
||||
height: img.naturalHeight
|
||||
}) as HTMLCanvasElement
|
||||
const ctx = canvas.getContext('2d')
|
||||
// @ts-expect-error fixme ts strict error
|
||||
let image
|
||||
if (!ctx) throw new Error('Failed to get canvas context')
|
||||
|
||||
let image: HTMLImageElement | ImageBitmap
|
||||
if (typeof window.createImageBitmap === 'undefined') {
|
||||
image = new Image()
|
||||
const p = new Promise((resolve, reject) => {
|
||||
// @ts-expect-error fixme ts strict error
|
||||
image.onload = resolve
|
||||
// @ts-expect-error fixme ts strict error
|
||||
image.onerror = reject
|
||||
const htmlImage = new Image()
|
||||
const objectUrl = URL.createObjectURL(blob)
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
htmlImage.onload = () => resolve()
|
||||
htmlImage.onerror = () => reject()
|
||||
}).finally(() => {
|
||||
// @ts-expect-error fixme ts strict error
|
||||
URL.revokeObjectURL(image.src)
|
||||
URL.revokeObjectURL(objectUrl)
|
||||
})
|
||||
image.src = URL.createObjectURL(blob)
|
||||
await p
|
||||
htmlImage.src = objectUrl
|
||||
image = htmlImage
|
||||
} else {
|
||||
image = await createImageBitmap(blob)
|
||||
}
|
||||
try {
|
||||
// @ts-expect-error fixme ts strict error
|
||||
ctx.drawImage(image, 0, 0)
|
||||
canvas.toBlob(writeImage, 'image/png')
|
||||
} finally {
|
||||
// @ts-expect-error fixme ts strict error
|
||||
if (typeof image.close === 'function') {
|
||||
// @ts-expect-error fixme ts strict error
|
||||
if ('close' in image && typeof image.close === 'function') {
|
||||
image.close()
|
||||
}
|
||||
}
|
||||
@@ -569,11 +566,10 @@ export const useLitegraphService = () => {
|
||||
throw error
|
||||
}
|
||||
} catch (error) {
|
||||
const message =
|
||||
error instanceof Error ? error.message : String(error)
|
||||
toastStore.addAlert(
|
||||
t('toastMessages.errorCopyImage', {
|
||||
// @ts-expect-error fixme ts strict error
|
||||
error: error.message ?? error
|
||||
})
|
||||
t('toastMessages.errorCopyImage', { error: message })
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,6 @@ vi.mock('@/config/version', () => ({
|
||||
__COMFYUI_FRONTEND_VERSION__: '1.24.0'
|
||||
}))
|
||||
|
||||
//@ts-expect-error Define global for the test
|
||||
global.__COMFYUI_FRONTEND_VERSION__ = '1.24.0'
|
||||
|
||||
import type { newUserService as NewUserServiceType } from '@/services/newUserService'
|
||||
|
||||
describe('newUserService', () => {
|
||||
|
||||
@@ -1,29 +1,32 @@
|
||||
import type { TWidgetValue } from '@/lib/litegraph/src/litegraph'
|
||||
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
|
||||
import type { ComfyNodeDefImpl } from '@/stores/nodeDefStore'
|
||||
|
||||
interface HasInputOrder {
|
||||
input_order?: Record<string, string[]>
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an ordered array of InputSpec objects based on input_order.
|
||||
* This is designed to work with V2 format used by litegraphService.
|
||||
*
|
||||
* @param nodeDefImpl - The ComfyNodeDefImpl containing both V1 and V2 formats
|
||||
* @param nodeDef - An object containing optional input_order
|
||||
* @param inputs - The V2 format inputs (flat Record<string, InputSpec>)
|
||||
* @returns Array of InputSpec objects in the correct order
|
||||
*/
|
||||
export function getOrderedInputSpecs(
|
||||
nodeDefImpl: ComfyNodeDefImpl,
|
||||
nodeDef: HasInputOrder | undefined,
|
||||
inputs: Record<string, InputSpec>
|
||||
): InputSpec[] {
|
||||
const orderedInputSpecs: InputSpec[] = []
|
||||
|
||||
// If no input_order, return default Object.values order
|
||||
if (!nodeDefImpl.input_order) {
|
||||
if (!nodeDef?.input_order) {
|
||||
return Object.values(inputs)
|
||||
}
|
||||
|
||||
// Process required inputs in specified order
|
||||
if (nodeDefImpl.input_order.required) {
|
||||
for (const name of nodeDefImpl.input_order.required) {
|
||||
if (nodeDef.input_order.required) {
|
||||
for (const name of nodeDef.input_order.required) {
|
||||
const inputSpec = inputs[name]
|
||||
if (inputSpec && !inputSpec.isOptional) {
|
||||
orderedInputSpecs.push(inputSpec)
|
||||
@@ -32,8 +35,8 @@ export function getOrderedInputSpecs(
|
||||
}
|
||||
|
||||
// Process optional inputs in specified order
|
||||
if (nodeDefImpl.input_order.optional) {
|
||||
for (const name of nodeDefImpl.input_order.optional) {
|
||||
if (nodeDef.input_order.optional) {
|
||||
for (const name of nodeDef.input_order.optional) {
|
||||
const inputSpec = inputs[name]
|
||||
if (inputSpec && inputSpec.isOptional) {
|
||||
orderedInputSpecs.push(inputSpec)
|
||||
|
||||
Reference in New Issue
Block a user