[fix] Improve type safety in keybinding migration

Replace 'any' type with proper 'Keybinding[]' type annotation in the
keybinding migration. Also create new objects during migration to avoid
mutating the original keybinding data, which follows immutability best
practices and prevents potential side effects.

This ensures better type checking and makes the migration code more
robust and maintainable.
This commit is contained in:
Benjamin Lu
2025-07-01 19:20:26 -04:00
parent c5edbe588c
commit bd0df83a7c

View File

@@ -40,13 +40,18 @@ export const SETTING_MIGRATIONS: SettingMigration[] = [
const settingStore = useSettingStore()
const keybindings = settingStore.get(
'Comfy.Keybinding.UnsetBindings'
) as any[]
) as Keybinding[]
const migrated = keybindings.map((keybinding) => {
if (keybinding['targetSelector'] === '#graph-canvas') {
keybinding['targetElementId'] = 'graph-canvas'
delete keybinding['targetSelector']
// Create a new object to avoid mutating the original
const newKeybinding = { ...keybinding }
if (
'targetSelector' in newKeybinding &&
newKeybinding['targetSelector'] === '#graph-canvas'
) {
newKeybinding['targetElementId'] = 'graph-canvas'
delete newKeybinding['targetSelector']
}
return keybinding
return newKeybinding
})
await settingStore.set('Comfy.Keybinding.UnsetBindings', migrated)
}