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:
Johnpaul Chiwetelu
2026-01-26 20:30:54 +01:00
committed by GitHub
parent 5769f96f55
commit b551064a6a
17 changed files with 201 additions and 143 deletions

View File

@@ -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
*/

View File

@@ -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')
})
})

View File

@@ -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
}