fix: improve type safety in type definitions (#7337)

## Summary

- Replace `any` types with proper TypeScript types in core type
definitions
- Add generics to `SettingParams`, `setting.get<T>()`, and
`setting.set<T>()` for type-safe setting access
- Add `NodeExecutionOutput` interface for `onExecuted` callback
- Change function parameters from `any` to `unknown` where appropriate

## Type Research

Performed GitHub code search across custom node repositories to
understand actual usage patterns:

**`onExecuted` output properties** (used in rgthree-comfy,
ComfyUI-KJNodes, ComfyUI-ExLlama-Nodes, comfy_mtb, etc.):
- `output.text` - string or string array for text display nodes
- `output.images`, `output.audio`, `output.video` - media outputs
- `output.ui.items` - complex debug/preview data with `input`, `text`,
`b64_images`

**`extensionManager.setting.get/set`** (used in ComfyUI-Crystools,
ComfyUI-Copilot, etc.):
- Returns various types (boolean, number, string, objects)
- Now uses generics: `setting.get<boolean>('MyExt.Setting')`

**`ComfyExtension` custom properties** (used in rgthree-comfy,
ComfyUI-Manager):
- `aboutPageBadges`, `commands`, custom methods
- Kept as `any` index signature since extensions add arbitrary
properties

## Changes

| File | Change |
|------|--------|
| `extensionTypes.ts` | Generic `setting.get<T>()` and
`setting.set<T>()`, typed Toast options |
| `litegraph-augmentation.d.ts` | `onExecuted(output:
NodeExecutionOutput)` |
| `metadataTypes.ts` | GLTF index signatures `any` → `unknown` |
| `apiSchema.ts` | New `NodeExecutionOutput` interface |
| `settings/types.ts` | `SettingOnChange<T>`, `SettingMigration<T>`,
`SettingParams<TValue>` |
| `nodeDefSchema.ts` | `validateComfyNodeDef(data: unknown)` |
| `workflowSchema.ts` | `isSubgraphDefinition(obj: unknown)` |
| `telemetry/types.ts` | `checkForCompletedTopup(events: AuditLog[])` |

## Test plan

- [x] `pnpm typecheck` passes
- [x] `pnpm test:unit` passes (3732 tests)
- [x] `pnpm lint` passes

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-7337-fix-improve-type-safety-in-type-definitions-2c66d73d365081bdbc30e916cac607d6)
by [Unito](https://www.unito.io)
This commit is contained in:
Johnpaul Chiwetelu
2025-12-11 22:10:01 +01:00
committed by GitHub
parent 3c8b7b015c
commit b9f75b6cc8
12 changed files with 51 additions and 35 deletions

View File

@@ -67,7 +67,7 @@ export interface ToastMessageOptions {
/**
* Detail content of the message.
*/
detail?: any | undefined
detail?: string
/**
* Whether the message can be closed manually using the close icon.
* @defaultValue true
@@ -84,11 +84,12 @@ export interface ToastMessageOptions {
/**
* Style class of the message.
*/
styleClass?: any
styleClass?: string | string[] | Record<string, boolean>
/**
* Style class of the content.
* Matches PrimeVue Toast API which accepts Vue class bindings.
*/
contentStyleClass?: any
contentStyleClass?: string | string[] | Record<string, boolean>
}
export type ToastManager = {
@@ -107,8 +108,8 @@ export interface ExtensionManager {
dialog: ReturnType<typeof useDialogService>
command: CommandManager
setting: {
get: (id: string) => any
set: (id: string, value: any) => void
get: <T = unknown>(id: string) => T | undefined
set: <T = unknown>(id: string, value: T) => void
}
}

View File

@@ -7,6 +7,7 @@ import type {
} from '@/lib/litegraph/src/litegraph'
import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets'
import type { NodeId } from '@/platform/workflow/validation/schemas/workflowSchema'
import type { NodeExecutionOutput } from '@/schemas/apiSchema'
import type { ComfyNodeDef as ComfyNodeDefV2 } from '@/schemas/nodeDef/nodeDefSchemaV2'
import type { ComfyNodeDef as ComfyNodeDefV1 } from '@/schemas/nodeDefSchema'
import type { DOMWidget, DOMWidgetOptions } from '@/scripts/domWidget'
@@ -94,7 +95,12 @@ declare module '@/lib/litegraph/src/litegraph' {
*/
onAfterGraphConfigured?(): void
onGraphConfigured?(): void
onExecuted?(output: any): void
/**
* Callback fired when node execution completes.
* Output contains known media properties (images, audio, video) plus
* arbitrary node-specific outputs (text, ui, custom properties).
*/
onExecuted?(output: NodeExecutionOutput): void
onNodeCreated?(this: LGraphNode): void
/** @deprecated groupNode */
setInnerNodes?(nodes: LGraphNode[]): void

View File

@@ -69,15 +69,15 @@ export type GltfChunkHeader = {
type GltfExtras = {
workflow?: string | object
prompt?: string | object
[key: string]: any
[key: string]: unknown
}
export type GltfJsonData = {
asset?: {
extras?: GltfExtras
[key: string]: any
[key: string]: unknown
}
[key: string]: any
[key: string]: unknown
}
/**