fix: replace as-unknown-as casts with safer patterns (#9107)

## Summary

- Replace 83 `as unknown as` double casts with safer alternatives across
33 files
- Use `as Partial<X> as X` pattern where TypeScript allows it
- Create/reuse factory functions from `litegraphTestUtils.ts` for mock
objects
- Widen `getWorkflowDataFromFile` return type to include `ComfyMetadata`
directly
- Reduce total `as unknown as` count from ~153 to 71

The remaining 71 occurrences are genuinely necessary due to cross-schema
casts, generic variance, missing index signatures, Float64Array-to-tuple
conversions, and DOM type incompatibilities.

## Test plan

- [x] `pnpm typecheck` passes
- [x] `pnpm lint` passes
- [x] All affected unit tests pass

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-9107-fix-replace-as-unknown-as-casts-with-safer-patterns-3106d73d3650815cb5bcd613ad635bd7)
by [Unito](https://www.unito.io)
This commit is contained in:
Johnpaul Chiwetelu
2026-02-23 05:46:12 +01:00
committed by GitHub
parent 8998d92e1b
commit 02e926471f
33 changed files with 282 additions and 346 deletions

View File

@@ -6,8 +6,8 @@ import type { Ref } from 'vue'
import QueueInlineProgress from '@/components/queue/QueueInlineProgress.vue'
const mockProgress = vi.hoisted(() => ({
totalPercent: null as unknown as Ref<number>,
currentNodePercent: null as unknown as Ref<number>
totalPercent: null! as Ref<number>,
currentNodePercent: null! as Ref<number>
}))
vi.mock('@/composables/queue/useQueueProgress', () => ({

View File

@@ -39,7 +39,7 @@ describe('useJobErrorReporting', () => {
dialog = {
showErrorDialog,
showExecutionErrorDialog
} as unknown as JobErrorDialogService
} as Partial<JobErrorDialogService> as JobErrorDialogService
composable = useJobErrorReporting({
taskForJob,
copyToClipboard: copyToClipboard as (

View File

@@ -31,7 +31,10 @@ function createFilter(
filterDef: {
id,
matches: vi.fn(() => true)
} as unknown as FuseFilter<ComfyNodeDefImpl, string>,
} as Partial<FuseFilter<ComfyNodeDefImpl, string>> as FuseFilter<
ComfyNodeDefImpl,
string
>,
value
}
}
@@ -43,7 +46,10 @@ function createActiveFilter(label: string): FilterChip {
filter: {
id: label.toLowerCase(),
matches: vi.fn(() => true)
} as unknown as FuseFilter<ComfyNodeDefImpl, string>
} as Partial<FuseFilter<ComfyNodeDefImpl, string>> as FuseFilter<
ComfyNodeDefImpl,
string
>
}
}