From bd0df83a7c2a2771a9ba88162449a7de32b4e29a Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Tue, 1 Jul 2025 19:20:26 -0400 Subject: [PATCH] [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. --- src/utils/migration/settingsMigration.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/utils/migration/settingsMigration.ts b/src/utils/migration/settingsMigration.ts index 95a3a2e73..cc392136b 100644 --- a/src/utils/migration/settingsMigration.ts +++ b/src/utils/migration/settingsMigration.ts @@ -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) }