Comfy-Org / Comfy-Org/ComfyUI_frontend

[TypeScript] Incomplete generic typing in SettingParams interface

Open
#4,405 5 comments 0 reactions 0 assignees View on GitHub
developer experience Public API verified bug
Dominant language
TypeScript
Stars
2k
Forks
702
Avg merge
1d 8h
Merged PRs (30d)
512

Description

## Problem

The `SettingParams` interface introduces a generic type parameter but doesn't use it consistently across all value-related properties:

```typescript
export interface SettingParams extends FormItem {
id: keyof Settings
defaultValue: any < /dev/null | (() => any) // ❌ Still using 'any'
defaultsByInstallVersion?: Record<`${number}.${number}.${number}`, TValue> // ✅ Uses TValue
onChange?: (newValue: any, oldValue?: any) => void // ❌ Still using 'any'
migrateDeprecatedValue?: (value: any) => any // ❌ Still using 'any'
}
```

## Current Behavior

```typescript
// With current implementation:
const boolSetting: SettingParams = {
id: 'Comfy.SomeSetting',
defaultValue: "not a boolean", // ❌ TypeScript won't catch this\!
defaultsByInstallVersion: {
"1.0.0": "also not boolean" // ✅ TypeScript WILL catch this
}
}
```

## Expected Behavior

```typescript
export interface SettingParams extends FormItem {
id: keyof Settings
defaultValue: TValue | (() => TValue) // ✅ Type-safe
defaultsByInstallVersion?: Record<`${number}.${number}.${number}`, TValue> // ✅ Already good
onChange?: (newValue: TValue, oldValue?: TValue) => void // ✅ Type-safe
migrateDeprecatedValue?: (value: unknown) => TValue // ✅ Type-safe migration
}
```

With proper typing:
```typescript
const boolSetting: SettingParams = {
id: 'Comfy.SomeSetting',
defaultValue: "not a boolean", // ✅ TypeScript error: Type 'string' is not assignable to type 'boolean'
defaultsByInstallVersion: {
"1.0.0": true // ✅ Correct
}
}
```

## Proposed Solution

Update the `SettingParams` interface in `src/types/settingTypes.ts` to consistently use the generic `TValue` parameter for all value-related properties.

┆Issue is synchronized with this [Notion page](https://www.notion.so/Issue-4405-TypeScript-Incomplete-generic-typing-in-SettingParams-interface-22b6d73d365081b68215e001e73597de) by [Unito](https://www.unito.io)

Contributor guide

Open the contributing guide

Research direction

Start in src/types/settingTypes.ts and inspect the SettingParams interface and its value-related properties. Update the typing so the generic TValue is applied consistently as described, then verify that boolean settings reject string defaults and that migration and change-handler types remain consistent.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.