mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-28 10:44:12 +00:00
Road to No Explicit Any Part 10 (#8499)
## Summary This PR removes `any` types from UI component files and replaces them with proper TypeScript types. ### Key Changes #### Type Safety Improvements - Replaced `any` with `unknown`, explicit types, or proper interfaces across UI components - Used `ComponentPublicInstance` with explicit method signatures for component refs - Used `Record<string, unknown>` for dynamic property access - Added generics for form components with flexible value types - Used `CSSProperties` for style objects ### Files Changed UI Components: - src/components/common/ComfyImage.vue - Used proper class prop type - src/components/common/DeviceInfo.vue - Used `string | number` for formatValue - src/components/common/FormItem.vue - Used `unknown` for model value - src/components/common/FormRadioGroup.vue - Added generic type parameter - src/components/common/TreeExplorer.vue - Used proper async function signature - src/components/custom/widget/WorkflowTemplateSelectorDialog.vue - Fixed duplicate import - src/components/graph/CanvasModeSelector.vue - Used `ComponentPublicInstance` for ref - src/components/node/NodePreview.vue - Changed `any` to `unknown` - src/components/queue/job/JobDetailsPopover.vue - Removed unnecessary casts - src/components/queue/job/JobFiltersBar.vue - Removed `as any` casts - src/platform/assets/components/MediaAssetContextMenu.vue - Added `ContextMenuInstance` type - src/renderer/extensions/minimap/MiniMapPanel.vue - Used `CSSProperties` - src/renderer/extensions/vueNodes/composables/useNodeTooltips.ts - Added `PrimeVueTooltipElement` interface - src/renderer/extensions/vueNodes/widgets/components/form/FormSelectButton.vue - Used `Record<string, unknown>` - src/workbench/extensions/manager/components/manager/infoPanel/tabs/DescriptionTabPanel.vue - Added `LicenseObject` interface ### Testing - All TypeScript type checking passes (`pnpm typecheck`) - Linting passes without errors (`pnpm lint`) Part of the "Road to No Explicit Any" initiative. ### Previous PRs in this series: - Part 2: #7401 - Part 3: #7935 - Part 4: #7970 - Part 5: #8064 - Part 6: #8083 - Part 7: #8092 - Part 8 Group 1: #8253 - Part 8 Group 2: #8258 - Part 8 Group 3: #8304 - Part 8 Group 4: #8314 - Part 8 Group 5: #8329 - Part 8 Group 6: #8344 - Part 8 Group 7: #8459 - Part 8 Group 8: #8496 - Part 9: #8498 - Part 10: #8499 ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-8499-Road-to-No-Explicit-Any-Part-10-2f86d73d365081aab129f165c7d02434) by [Unito](https://www.unito.io)
This commit is contained in:
committed by
GitHub
parent
7dd3098af5
commit
cfdd002b7c
@@ -79,11 +79,12 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import Checkbox from 'primevue/checkbox'
|
||||
import type { CSSProperties } from 'vue'
|
||||
|
||||
import type { MinimapSettingsKey } from '@/renderer/extensions/minimap/types'
|
||||
|
||||
defineProps<{
|
||||
panelStyles: any
|
||||
panelStyles: CSSProperties
|
||||
nodeColors: boolean
|
||||
showLinks: boolean
|
||||
showGroups: boolean
|
||||
|
||||
@@ -12,6 +12,11 @@ import { useNodeDefStore } from '@/stores/nodeDefStore'
|
||||
import { normalizeI18nKey } from '@/utils/formatUtil'
|
||||
import { cn } from '@/utils/tailwindUtil'
|
||||
|
||||
// PrimeVue adds this internal property to elements with tooltips
|
||||
interface PrimeVueTooltipElement extends Element {
|
||||
$_ptooltipId?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide all visible tooltips by dispatching mouseleave events
|
||||
*
|
||||
@@ -41,7 +46,7 @@ const hideTooltipsGlobally = () => {
|
||||
// Find the target element that owns this tooltip
|
||||
const targetElements = document.querySelectorAll('[data-pd-tooltip="true"]')
|
||||
for (const targetEl of targetElements) {
|
||||
if ((targetEl as any).$_ptooltipId === tooltipId) {
|
||||
if ((targetEl as PrimeVueTooltipElement).$_ptooltipId === tooltipId) {
|
||||
;(targetEl as HTMLElement).dispatchEvent(
|
||||
new MouseEvent('mouseleave', { bubbles: true })
|
||||
)
|
||||
|
||||
@@ -76,25 +76,27 @@ const getOptionValue = (option: T, index: number): ModelValue => {
|
||||
}
|
||||
|
||||
const valueField = props.optionValue
|
||||
const optionRecord = option as Record<string, unknown>
|
||||
const value =
|
||||
(option as any)[valueField] ??
|
||||
optionRecord[valueField] ??
|
||||
option.value ??
|
||||
(option as any).name ??
|
||||
optionRecord.name ??
|
||||
option.label ??
|
||||
index
|
||||
return value
|
||||
return value as ModelValue
|
||||
}
|
||||
|
||||
// for display with PrimeVue compatibility
|
||||
const getOptionLabel = (option: T): string => {
|
||||
if (typeof option === 'object' && option !== null) {
|
||||
const labelField = props.optionLabel
|
||||
return (
|
||||
(option as any)[labelField] ??
|
||||
option.label ??
|
||||
(option as any).name ??
|
||||
option.value ??
|
||||
String(option)
|
||||
const optionRecord = option as Record<string, unknown>
|
||||
return String(
|
||||
optionRecord[labelField] ??
|
||||
option.label ??
|
||||
optionRecord.name ??
|
||||
option.value ??
|
||||
option
|
||||
)
|
||||
}
|
||||
return String(option)
|
||||
|
||||
Reference in New Issue
Block a user