mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-28 10:12:11 +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
@@ -67,7 +67,7 @@ const MOCK_ASSETS = {
|
||||
} as const
|
||||
|
||||
// Helper functions
|
||||
function mockApiResponse(assets: any[], options = {}) {
|
||||
function mockApiResponse(assets: unknown[], options = {}) {
|
||||
const response = {
|
||||
assets,
|
||||
total: assets.length,
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -37,6 +37,13 @@ export interface SurveyResponses {
|
||||
making?: string[]
|
||||
}
|
||||
|
||||
export interface SurveyResponsesNormalized extends SurveyResponses {
|
||||
industry_normalized?: string
|
||||
industry_raw?: string
|
||||
useCase_normalized?: string
|
||||
useCase_raw?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Run button tracking properties
|
||||
*/
|
||||
|
||||
@@ -328,9 +328,9 @@ describe('normalizeIndustry', () => {
|
||||
})
|
||||
|
||||
it('should handle null and invalid inputs', () => {
|
||||
expect(normalizeIndustry(null as any)).toBe('Other / Undefined')
|
||||
expect(normalizeIndustry(undefined as any)).toBe('Other / Undefined')
|
||||
expect(normalizeIndustry(123 as any)).toBe('Other / Undefined')
|
||||
expect(normalizeIndustry(null)).toBe('Other / Undefined')
|
||||
expect(normalizeIndustry(undefined)).toBe('Other / Undefined')
|
||||
expect(normalizeIndustry(123)).toBe('Other / Undefined')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -508,7 +508,7 @@ describe('normalizeUseCase', () => {
|
||||
expect(normalizeUseCase('none')).toBe('Other / Undefined')
|
||||
expect(normalizeUseCase('undefined')).toBe('Other / Undefined')
|
||||
expect(normalizeUseCase('')).toBe('Other / Undefined')
|
||||
expect(normalizeUseCase(null as any)).toBe('Other / Undefined')
|
||||
expect(normalizeUseCase(null)).toBe('Other / Undefined')
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* Uses Fuse.js for fuzzy matching against category keywords.
|
||||
*/
|
||||
import Fuse from 'fuse.js'
|
||||
import type { SurveyResponses, SurveyResponsesNormalized } from '../types'
|
||||
|
||||
interface CategoryMapping {
|
||||
name: string
|
||||
@@ -583,21 +584,19 @@ export function normalizeUseCase(rawUseCase: unknown): string {
|
||||
* Apply normalization to survey responses
|
||||
* Creates both normalized and raw versions of responses
|
||||
*/
|
||||
export function normalizeSurveyResponses(responses: {
|
||||
industry?: string
|
||||
useCase?: string
|
||||
[key: string]: any
|
||||
}) {
|
||||
const normalized = { ...responses }
|
||||
export function normalizeSurveyResponses(
|
||||
responses: SurveyResponses
|
||||
): SurveyResponsesNormalized {
|
||||
const normalized: SurveyResponsesNormalized = { ...responses }
|
||||
|
||||
// Normalize industry
|
||||
if (responses.industry) {
|
||||
if (typeof responses.industry === 'string') {
|
||||
normalized.industry_normalized = normalizeIndustry(responses.industry)
|
||||
normalized.industry_raw = responses.industry
|
||||
}
|
||||
|
||||
// Normalize use case
|
||||
if (responses.useCase) {
|
||||
if (typeof responses.useCase === 'string') {
|
||||
normalized.useCase_normalized = normalizeUseCase(responses.useCase)
|
||||
normalized.useCase_raw = responses.useCase
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user