From 444ca5db9ee456cca68e233524a33f125b66efbc Mon Sep 17 00:00:00 2001 From: Arjan Singh Date: Wed, 10 Sep 2025 21:50:18 -0700 Subject: [PATCH] [fix] some typescript issues in src/composables --- src/composables/useCivitaiModel.ts | 9 ++++++++- src/composables/useConflictDetection.ts | 12 +++++++----- src/composables/useContextMenuTranslation.ts | 17 ++++++++++++----- src/composables/useCoreCommands.ts | 6 +++--- src/composables/useDownload.ts | 2 +- src/composables/useErrorHandling.ts | 4 ++-- src/composables/useLoad3dViewer.ts | 7 +++++-- 7 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/composables/useCivitaiModel.ts b/src/composables/useCivitaiModel.ts index c47b27483..e33053730 100644 --- a/src/composables/useCivitaiModel.ts +++ b/src/composables/useCivitaiModel.ts @@ -36,7 +36,14 @@ interface CivitaiModelVersionResponse { model: CivitaiModel modelId: number files: CivitaiModelFile[] - [key: string]: any + // Common optional Civitai API fields + createdAt?: string + publishedAt?: string + trainedWords?: string[] + stats?: Record + description?: string + // Allow additional API evolution + [key: string]: string | number | boolean | object | undefined } /** diff --git a/src/composables/useConflictDetection.ts b/src/composables/useConflictDetection.ts index abf4d9498..d8122bec5 100644 --- a/src/composables/useConflictDetection.ts +++ b/src/composables/useConflictDetection.ts @@ -220,9 +220,9 @@ export function useConflictDetection() { abortController.value?.signal ) - if (bulkResponse && bulkResponse.node_versions) { + if (bulkResponse?.node_versions) { // Process bulk response - bulkResponse.node_versions.forEach((result) => { + bulkResponse?.node_versions?.forEach((result) => { if (result.status === 'success' && result.node_version) { versionDataMap.set( result.identifier.node_id, @@ -265,7 +265,7 @@ export function useConflictDetection() { const requirement: NodePackRequirements = { // Basic package info id: packageId, - name: packInfo?.name || packageId, + name: packInfo?.name ?? packageId, installed_version: installedVersion, is_enabled: isEnabled, @@ -291,7 +291,7 @@ export function useConflictDetection() { // Create fallback requirement without Registry data const fallbackRequirement: NodePackRequirements = { id: packageId, - name: packInfo?.name || packageId, + name: packInfo?.name ?? packageId, installed_version: installedVersion, is_enabled: isEnabled, is_banned: false, @@ -326,7 +326,9 @@ export function useConflictDetection() { const conflicts: ConflictDetail[] = [] // Helper function to check if a value indicates "compatible with all" - const isCompatibleWithAll = (value: any): boolean => { + const isCompatibleWithAll = ( + value: string | string[] | null | undefined + ): boolean => { if (value === null || value === undefined) return true if (typeof value === 'string' && value.trim() === '') return true if (Array.isArray(value) && value.length === 0) return true diff --git a/src/composables/useContextMenuTranslation.ts b/src/composables/useContextMenuTranslation.ts index 1fd851420..b01b4106d 100644 --- a/src/composables/useContextMenuTranslation.ts +++ b/src/composables/useContextMenuTranslation.ts @@ -8,6 +8,11 @@ import type { import { LGraphCanvas, LiteGraph } from '@/lib/litegraph/src/litegraph' import { normalizeI18nKey } from '@/utils/formatUtil' +interface ContextMenuExtraInfo { + inputs?: INodeInputSlot[] + widgets?: IWidget[] +} + /** * Add translation for litegraph context menu. */ @@ -50,18 +55,20 @@ export const useContextMenuTranslation = () => { } // for capture translation text of input and widget - const extraInfo: any = options.extra || options.parentMenu?.options?.extra + const extraInfo: ContextMenuExtraInfo | undefined = + (options.extra as ContextMenuExtraInfo) || + (options.parentMenu?.options?.extra as ContextMenuExtraInfo) // widgets and inputs const matchInput = value.content?.match(reInput) if (matchInput) { let match = matchInput[1] extraInfo?.inputs?.find((i: INodeInputSlot) => { if (i.name != match) return false - match = i.label ? i.label : i.name + match = i.label ?? i.name }) extraInfo?.widgets?.find((i: IWidget) => { if (i.name != match) return false - match = i.label ? i.label : i.name + match = i.label ?? i.name }) value.content = cvt + match + tinp continue @@ -71,11 +78,11 @@ export const useContextMenuTranslation = () => { let match = matchWidget[1] extraInfo?.inputs?.find((i: INodeInputSlot) => { if (i.name != match) return false - match = i.label ? i.label : i.name + match = i.label ?? i.name }) extraInfo?.widgets?.find((i: IWidget) => { if (i.name != match) return false - match = i.label ? i.label : i.name + match = i.label ?? i.name }) value.content = cvt + match + twgt continue diff --git a/src/composables/useCoreCommands.ts b/src/composables/useCoreCommands.ts index ad3378209..585a67106 100644 --- a/src/composables/useCoreCommands.ts +++ b/src/composables/useCoreCommands.ts @@ -30,7 +30,7 @@ import { useSettingStore } from '@/stores/settingStore' import { useSubgraphNavigationStore } from '@/stores/subgraphNavigationStore' import { useSubgraphStore } from '@/stores/subgraphStore' import { useToastStore } from '@/stores/toastStore' -import { type ComfyWorkflow, useWorkflowStore } from '@/stores/workflowStore' +import { useWorkflowStore } from '@/stores/workflowStore' import { useBottomPanelStore } from '@/stores/workspace/bottomPanelStore' import { useColorPaletteStore } from '@/stores/workspace/colorPaletteStore' import { useSearchBoxStore } from '@/stores/workspace/searchBoxStore' @@ -106,7 +106,7 @@ export function useCoreCommands(): ComfyCommand[] { menubarLabel: 'Save', category: 'essentials' as const, function: async () => { - const workflow = useWorkflowStore().activeWorkflow as ComfyWorkflow + const workflow = useWorkflowStore().activeWorkflow if (!workflow) return await workflowService.saveWorkflow(workflow) @@ -128,7 +128,7 @@ export function useCoreCommands(): ComfyCommand[] { menubarLabel: 'Save As', category: 'essentials' as const, function: async () => { - const workflow = useWorkflowStore().activeWorkflow as ComfyWorkflow + const workflow = useWorkflowStore().activeWorkflow if (!workflow) return await workflowService.saveWorkflowAs(workflow) diff --git a/src/composables/useDownload.ts b/src/composables/useDownload.ts index 2b1d8924a..f25b867f0 100644 --- a/src/composables/useDownload.ts +++ b/src/composables/useDownload.ts @@ -41,7 +41,7 @@ export function useDownload(url: string, fileName?: string) { link.href = downloadUrlToHfRepoUrl(url) } else { link.href = url - link.download = fileName || url.split('/').pop() || 'download' + link.download = fileName ?? url.split('/').pop() ?? 'download' } link.target = '_blank' // Opens in new tab if download attribute is not supported link.rel = 'noopener noreferrer' // Security best practice for _blank links diff --git a/src/composables/useErrorHandling.ts b/src/composables/useErrorHandling.ts index 607997ac8..b21e35583 100644 --- a/src/composables/useErrorHandling.ts +++ b/src/composables/useErrorHandling.ts @@ -13,7 +13,7 @@ export function useErrorHandling() { } const wrapWithErrorHandling = - ( + ( action: (...args: TArgs) => TReturn, errorHandler?: (error: any) => void, finallyHandler?: () => void @@ -29,7 +29,7 @@ export function useErrorHandling() { } const wrapWithErrorHandlingAsync = - ( + ( action: (...args: TArgs) => Promise | TReturn, errorHandler?: (error: any) => void, finallyHandler?: () => void diff --git a/src/composables/useLoad3dViewer.ts b/src/composables/useLoad3dViewer.ts index 4066787fc..eb8d0dc21 100644 --- a/src/composables/useLoad3dViewer.ts +++ b/src/composables/useLoad3dViewer.ts @@ -3,6 +3,7 @@ import { ref, toRaw, watch } from 'vue' import Load3d from '@/extensions/core/load3d/Load3d' import Load3dUtils from '@/extensions/core/load3d/Load3dUtils' import { + CameraState, CameraType, MaterialMode, UpDirection @@ -18,7 +19,7 @@ interface Load3dViewerState { cameraType: CameraType fov: number lightIntensity: number - cameraState: any + cameraState: CameraState | null backgroundImage: string upDirection: UpDirection materialMode: MaterialMode @@ -274,7 +275,9 @@ export const useLoad3dViewer = (node: LGraphNode) => { nodeValue.properties['FOV'] = initialState.value.fov nodeValue.properties['Light Intensity'] = initialState.value.lightIntensity - nodeValue.properties['Camera Info'] = initialState.value.cameraState + if (initialState.value.cameraState) { + nodeValue.properties['Camera Info'] = initialState.value.cameraState + } nodeValue.properties['Background Image'] = initialState.value.backgroundImage }