mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-01 19:51:54 +00:00
## 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)
63 lines
1.5 KiB
Vue
63 lines
1.5 KiB
Vue
<template>
|
|
<div class="flex flex-row gap-4">
|
|
<div
|
|
v-for="option in normalizedOptions"
|
|
:key="option.value"
|
|
class="flex items-center"
|
|
>
|
|
<RadioButton
|
|
:input-id="`${id}-${option.value}`"
|
|
:name="id"
|
|
:value="option.value"
|
|
:model-value="modelValue"
|
|
:aria-describedby="`${option.text}-label`"
|
|
@update:model-value="$emit('update:modelValue', $event)"
|
|
/>
|
|
<label :for="`${id}-${option.value}`" class="ml-2 cursor-pointer">
|
|
{{ option.text }}
|
|
</label>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts" generic="T extends string | number | boolean | null">
|
|
import RadioButton from 'primevue/radiobutton'
|
|
import { computed } from 'vue'
|
|
|
|
import type { SettingOption } from '@/platform/settings/types'
|
|
|
|
const props = defineProps<{
|
|
modelValue: T
|
|
options?: (string | SettingOption | Record<string, string>)[]
|
|
optionLabel?: string
|
|
optionValue?: string
|
|
id?: string
|
|
}>()
|
|
|
|
defineEmits<{
|
|
'update:modelValue': [value: T]
|
|
}>()
|
|
|
|
const normalizedOptions = computed<SettingOption[]>(() => {
|
|
if (!props.options) return []
|
|
|
|
return props.options.map((option) => {
|
|
if (typeof option === 'string') {
|
|
return { text: option, value: option }
|
|
}
|
|
|
|
if ('text' in option) {
|
|
return {
|
|
text: option.text,
|
|
value: option.value ?? option.text
|
|
}
|
|
}
|
|
// Handle optionLabel/optionValue
|
|
return {
|
|
text: option[props.optionLabel || 'text'] || 'Unknown',
|
|
value: option[props.optionValue || 'value']
|
|
}
|
|
})
|
|
})
|
|
</script>
|