mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-28 02:02:08 +00:00
Road to No Explicit Any Part 8 (Group4) (#8314)
## Summary Removes all `as unknown as Type` double-cast patterns from group 4 files as part of the ongoing TypeScript cleanup effort. ## Changes ### Type Safety Improvements - Replaced `as unknown as Type` with `as Partial<Type> as Type` for valid mock objects - Added proper null/undefined validation in `Subgraph.addInput()` and `Subgraph.addOutput()` - Updated test expectations to match new validation behavior ### Files Modified (17 files) **Core Implementation:** - `src/lib/litegraph/src/LGraph.ts` - Added input validation for subgraph add methods - `src/lib/litegraph/src/interfaces.ts` - Cleaned up type definitions - `src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts` - Improved type safety - `src/platform/telemetry/types.ts` - Better type definitions - `src/platform/telemetry/utils/surveyNormalization.ts` - Type cleanup **Test Files:** - `src/lib/litegraph/src/subgraph/SubgraphEdgeCases.test.ts` - Updated to expect validation errors - `src/lib/litegraph/src/subgraph/SubgraphMemory.test.ts` - Proper mock typing - `src/lib/litegraph/src/subgraph/SubgraphNode.test.ts` - Type improvements - `src/lib/litegraph/src/subgraph/SubgraphNode.titleButton.test.ts` - Mock type fixes - `src/lib/litegraph/src/subgraph/SubgraphSlotVisualFeedback.test.ts` - Proper typing - `src/lib/litegraph/src/subgraph/SubgraphWidgetPromotion.test.ts` - Type cleanup - `src/lib/litegraph/src/utils/textUtils.test.ts` - Mock improvements - `src/lib/litegraph/src/widgets/ComboWidget.test.ts` - Type safety updates - `src/platform/assets/services/assetService.test.ts` - Type improvements - `src/platform/settings/composables/useSettingSearch.test.ts` - Mock type fixes - `src/platform/settings/settingStore.test.ts` - Type cleanup - `src/platform/telemetry/utils/__tests__/surveyNormalization.test.ts` - Type improvements ## Testing - ✅ All modified test files pass - ✅ TypeScript compilation passes - ✅ Linting passes ## Related Part of the TypeScript cleanup effort. Follows patterns from groups 1-3. Previous PRs: - Group 1: (merged) - Group 2: (merged) - Group 3: #8304 ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-8314-Road-to-No-Explicit-Any-Part-8-Group4-2f46d73d36508172a9d4e53b2c5cbadd) by [Unito](https://www.unito.io)
This commit is contained in:
committed by
GitHub
parent
5769f96f55
commit
b551064a6a
@@ -8,6 +8,17 @@ import {
|
||||
getSettingInfo,
|
||||
useSettingStore
|
||||
} from '@/platform/settings/settingStore'
|
||||
import type { SettingTreeNode } from '@/platform/settings/settingStore'
|
||||
|
||||
// Test-specific type for mock settings
|
||||
interface MockSettingParams {
|
||||
id: string
|
||||
name: string
|
||||
type: string
|
||||
defaultValue: unknown
|
||||
category?: string[]
|
||||
deprecated?: boolean
|
||||
}
|
||||
|
||||
// Mock dependencies
|
||||
vi.mock('@/i18n', () => ({
|
||||
@@ -20,8 +31,8 @@ vi.mock('@/platform/settings/settingStore', () => ({
|
||||
}))
|
||||
|
||||
describe('useSettingSearch', () => {
|
||||
let mockSettingStore: any
|
||||
let mockSettings: any
|
||||
let mockSettingStore: ReturnType<typeof useSettingStore>
|
||||
let mockSettings: Record<string, MockSettingParams>
|
||||
|
||||
beforeEach(() => {
|
||||
setActivePinia(createPinia())
|
||||
@@ -70,11 +81,11 @@ describe('useSettingSearch', () => {
|
||||
// Mock setting store
|
||||
mockSettingStore = {
|
||||
settingsById: mockSettings
|
||||
}
|
||||
} as ReturnType<typeof useSettingStore>
|
||||
vi.mocked(useSettingStore).mockReturnValue(mockSettingStore)
|
||||
|
||||
// Mock getSettingInfo function
|
||||
vi.mocked(getSettingInfo).mockImplementation((setting: any) => {
|
||||
vi.mocked(getSettingInfo).mockImplementation((setting) => {
|
||||
const parts = setting.category || setting.id.split('.')
|
||||
return {
|
||||
category: parts[0] ?? 'Other',
|
||||
@@ -301,8 +312,8 @@ describe('useSettingSearch', () => {
|
||||
const search = useSettingSearch()
|
||||
search.filteredSettingIds.value = ['Category.Setting1', 'Other.Setting3']
|
||||
|
||||
const activeCategory = { label: 'Category' } as any
|
||||
const results = search.getSearchResults(activeCategory)
|
||||
const activeCategory: Partial<SettingTreeNode> = { label: 'Category' }
|
||||
const results = search.getSearchResults(activeCategory as SettingTreeNode)
|
||||
|
||||
expect(results).toEqual([
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
useSettingStore
|
||||
} from '@/platform/settings/settingStore'
|
||||
import type { SettingParams } from '@/platform/settings/types'
|
||||
import type { Settings } from '@/schemas/apiSchema'
|
||||
import { api } from '@/scripts/api'
|
||||
import { app } from '@/scripts/app'
|
||||
|
||||
@@ -45,7 +46,9 @@ describe('useSettingStore', () => {
|
||||
describe('loadSettingValues', () => {
|
||||
it('should load settings from API', async () => {
|
||||
const mockSettings = { 'test.setting': 'value' }
|
||||
vi.mocked(api.getSettings).mockResolvedValue(mockSettings as any)
|
||||
vi.mocked(api.getSettings).mockResolvedValue(
|
||||
mockSettings as Partial<Settings> as Settings
|
||||
)
|
||||
|
||||
await store.loadSettingValues()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user