Comfy-Org / Comfy-Org/ComfyUI_frontend
[TypeScript] Incomplete generic typing in SettingParams interface
- 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
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