Skip to content

Commit e03303e

Browse files
webfilteredlordTyrion
authored andcommitted
[TS] Improve various types / remove assertions (Comfy-Org#4148)
1 parent 9840247 commit e03303e

File tree

6 files changed

+33
-59
lines changed

6 files changed

+33
-59
lines changed

src/stores/executionStore.ts

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -92,50 +92,26 @@ export const useExecutionStore = defineStore('execution', () => {
9292
})
9393

9494
function bindExecutionEvents() {
95-
api.addEventListener(
96-
'execution_start',
97-
handleExecutionStart as EventListener
98-
)
99-
api.addEventListener(
100-
'execution_cached',
101-
handleExecutionCached as EventListener
102-
)
103-
api.addEventListener('executed', handleExecuted as EventListener)
104-
api.addEventListener('executing', handleExecuting as EventListener)
105-
api.addEventListener('progress', handleProgress as EventListener)
106-
api.addEventListener('status', handleStatus as EventListener)
107-
api.addEventListener(
108-
'execution_error',
109-
handleExecutionError as EventListener
110-
)
95+
api.addEventListener('execution_start', handleExecutionStart)
96+
api.addEventListener('execution_cached', handleExecutionCached)
97+
api.addEventListener('executed', handleExecuted)
98+
api.addEventListener('executing', handleExecuting)
99+
api.addEventListener('progress', handleProgress)
100+
api.addEventListener('status', handleStatus)
101+
api.addEventListener('execution_error', handleExecutionError)
111102
}
112-
api.addEventListener('progress_text', handleProgressText as EventListener)
113-
api.addEventListener(
114-
'display_component',
115-
handleDisplayComponent as EventListener
116-
)
103+
api.addEventListener('progress_text', handleProgressText)
104+
api.addEventListener('display_component', handleDisplayComponent)
117105

118106
function unbindExecutionEvents() {
119-
api.removeEventListener(
120-
'execution_start',
121-
handleExecutionStart as EventListener
122-
)
123-
api.removeEventListener(
124-
'execution_cached',
125-
handleExecutionCached as EventListener
126-
)
127-
api.removeEventListener('executed', handleExecuted as EventListener)
128-
api.removeEventListener('executing', handleExecuting as EventListener)
129-
api.removeEventListener('progress', handleProgress as EventListener)
130-
api.removeEventListener('status', handleStatus as EventListener)
131-
api.removeEventListener(
132-
'execution_error',
133-
handleExecutionError as EventListener
134-
)
135-
api.removeEventListener(
136-
'progress_text',
137-
handleProgressText as EventListener
138-
)
107+
api.removeEventListener('execution_start', handleExecutionStart)
108+
api.removeEventListener('execution_cached', handleExecutionCached)
109+
api.removeEventListener('executed', handleExecuted)
110+
api.removeEventListener('executing', handleExecuting)
111+
api.removeEventListener('progress', handleProgress)
112+
api.removeEventListener('status', handleStatus)
113+
api.removeEventListener('execution_error', handleExecutionError)
114+
api.removeEventListener('progress_text', handleProgressText)
139115
}
140116

141117
function handleExecutionStart(e: CustomEvent<ExecutionStartWsMessage>) {
@@ -184,7 +160,7 @@ export const useExecutionStore = defineStore('execution', () => {
184160
clientId.value = api.clientId
185161

186162
// Once we've received the clientId we no longer need to listen
187-
api.removeEventListener('status', handleStatus as EventListener)
163+
api.removeEventListener('status', handleStatus)
188164
}
189165
}
190166

src/types/treeExplorerTypes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import type { InjectionKey, ModelRef } from 'vue'
44

55
export interface TreeNode extends PrimeVueTreeNode {
66
label: string
7-
children?: TreeNode[]
7+
children?: this[]
88
}
99

1010
export interface TreeExplorerNode<T = any> extends TreeNode {
1111
data?: T
12-
children?: TreeExplorerNode<T>[]
12+
children?: this[]
1313
icon?: string
1414
/**
1515
* Function to override what icon to use for the node.
@@ -62,7 +62,7 @@ export interface TreeExplorerNode<T = any> extends TreeNode {
6262
}
6363

6464
export interface RenderedTreeExplorerNode<T = any> extends TreeExplorerNode<T> {
65-
children?: RenderedTreeExplorerNode<T>[]
65+
children?: this[]
6666
icon: string
6767
type: 'folder' | 'node'
6868
/** Total number of leaves in the subtree */

src/utils/nodeDefUtil.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ const mergeNumericInputSpec = <T extends IntInputSpec | FloatInputSpec>(
6161
}
6262

6363
return mergeCommonInputSpec(
64-
[type, { ...options1, ...mergedOptions }] as unknown as T,
65-
[type, { ...options2, ...mergedOptions }] as unknown as T
64+
[type, { ...options1, ...mergedOptions }] as T,
65+
[type, { ...options2, ...mergedOptions }] as T
6666
)
6767
}
6868

@@ -84,8 +84,8 @@ const mergeComboInputSpec = <T extends ComboInputSpec | ComboInputSpecV2>(
8484
}
8585

8686
return mergeCommonInputSpec(
87-
['COMBO', { ...options1, options: intersection }] as unknown as T,
88-
['COMBO', { ...options2, options: intersection }] as unknown as T
87+
['COMBO', { ...options1, options: intersection }] as T,
88+
['COMBO', { ...options2, options: intersection }] as T
8989
)
9090
}
9191

@@ -107,9 +107,7 @@ const mergeCommonInputSpec = <T extends InputSpec>(
107107
return value1 === value2 || (_.isNil(value1) && _.isNil(value2))
108108
})
109109

110-
return mergeIsValid
111-
? ([type, { ...options1, ...options2 }] as unknown as T)
112-
: null
110+
return mergeIsValid ? ([type, { ...options1, ...options2 }] as T) : null
113111
}
114112

115113
/**

src/utils/treeUtil.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export const findNodeByKey = <T extends TreeNode>(
116116
return null
117117
}
118118
for (const child of root.children) {
119-
const result = findNodeByKey(child as T, key)
119+
const result = findNodeByKey(child, key)
120120
if (result) {
121121
return result
122122
}
@@ -130,11 +130,11 @@ export const findNodeByKey = <T extends TreeNode>(
130130
* @returns A deep clone of the node.
131131
*/
132132
export function cloneTree<T extends TreeNode>(node: T): T {
133-
const clone: T = { ...node } as T
133+
const clone = { ...node }
134134

135135
// Clone children recursively
136136
if (node.children && node.children.length > 0) {
137-
clone.children = node.children.map((child) => cloneTree(child as T))
137+
clone.children = node.children.map((child) => cloneTree(child))
138138
}
139139

140140
return clone

vite.config.mts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import dotenv from 'dotenv'
33
import IconsResolver from 'unplugin-icons/resolver'
44
import Icons from 'unplugin-icons/vite'
55
import Components from 'unplugin-vue-components/vite'
6-
import { defineConfig } from 'vite'
6+
import { type UserConfig, defineConfig } from 'vite'
77
import { createHtmlPlugin } from 'vite-plugin-html'
88
import type { UserConfigExport } from 'vitest/config'
9+
import vueDevTools from 'vite-plugin-vue-devtools'
910

1011
import {
1112
addElementVnodeExportPlugin,
@@ -151,4 +152,4 @@ export default defineConfig({
151152
optimizeDeps: {
152153
exclude: ['@comfyorg/litegraph', '@comfyorg/comfyui-electron-types']
153154
}
154-
}) as UserConfigExport
155+
}) satisfies UserConfig as UserConfig

vite.electron.config.mts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Plugin, defineConfig } from 'vite'
22
import { mergeConfig } from 'vite'
3-
import type { UserConfig } from 'vitest/config'
43

54
import baseConfig from './vite.config.mts'
65

@@ -83,7 +82,7 @@ const mockElectronAPI: Plugin = {
8382
}
8483

8584
export default mergeConfig(
86-
baseConfig as unknown as UserConfig,
85+
baseConfig,
8786
defineConfig({
8887
plugins: [mockElectronAPI]
8988
})

0 commit comments

Comments
 (0)