mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-07 14:09:59 +00:00
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:
committed by
GitHub
parent
8998d92e1b
commit
02e926471f
@@ -104,7 +104,7 @@ describe('useAudioService', () => {
|
||||
const mockTrack2 = { stop: vi.fn() }
|
||||
const mockStream = {
|
||||
getTracks: vi.fn().mockReturnValue([mockTrack1, mockTrack2])
|
||||
} as unknown as MediaStream
|
||||
} as Partial<MediaStream> as MediaStream
|
||||
|
||||
service.stopAllTracks(mockStream)
|
||||
|
||||
@@ -120,7 +120,7 @@ describe('useAudioService', () => {
|
||||
it('should handle stream with no tracks', () => {
|
||||
const mockStream = {
|
||||
getTracks: vi.fn().mockReturnValue([])
|
||||
} as unknown as MediaStream
|
||||
} as Partial<MediaStream> as MediaStream
|
||||
|
||||
expect(() => service.stopAllTracks(mockStream)).not.toThrow()
|
||||
expect(mockStream.getTracks).toHaveBeenCalledTimes(1)
|
||||
@@ -135,7 +135,7 @@ describe('useAudioService', () => {
|
||||
}
|
||||
const mockStream = {
|
||||
getTracks: vi.fn().mockReturnValue([mockTrack1, mockTrack2])
|
||||
} as unknown as MediaStream
|
||||
} as Partial<MediaStream> as MediaStream
|
||||
|
||||
expect(() => service.stopAllTracks(mockStream)).toThrow()
|
||||
expect(mockTrack1.stop).toHaveBeenCalledTimes(1)
|
||||
|
||||
@@ -107,8 +107,7 @@ export const useColorPaletteService = () => {
|
||||
for (const dataType of nodeDefStore.nodeDataTypes) {
|
||||
const cssVar = `color-datatype-${dataType}`
|
||||
|
||||
const valueMaybe =
|
||||
linkColorPalette[dataType as unknown as keyof Colors['node_slot']]
|
||||
const valueMaybe = linkColorPalette[dataType as keyof Colors['node_slot']]
|
||||
if (valueMaybe) {
|
||||
rootStyle.setProperty(`--${cssVar}`, valueMaybe)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user