From 56e5c601a88e6d8ef36bab6e73bec2384d7e6551 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Wed, 13 Apr 2022 09:18:48 -0400 Subject: [PATCH] some more fixing type errors Signed-off-by: Sebastian Malton --- .../hotbar/hotbar-switch-command.tsx | 83 ++++++++++++------- src/renderer/components/table/react-table.tsx | 19 ++--- 2 files changed, 57 insertions(+), 45 deletions(-) diff --git a/src/renderer/components/hotbar/hotbar-switch-command.tsx b/src/renderer/components/hotbar/hotbar-switch-command.tsx index 5e58461268..f8e0f2a04f 100644 --- a/src/renderer/components/hotbar/hotbar-switch-command.tsx +++ b/src/renderer/components/hotbar/hotbar-switch-command.tsx @@ -25,21 +25,35 @@ interface Dependencies { commandOverlay: CommandOverlay; } -function ignoreIf(check: boolean, menuItems: T) { +function ignoreIf(check: boolean, menuItems: T[]): T[] { return check ? [] : menuItems; } -function getHotbarSwitchOptions(hotbars: Hotbar[]): (Hotbar | typeof hotbarAddAction | typeof hotbarRemoveAction | typeof hotbarRenameAction)[] { +interface HotbarSwitchActionOption { + action: typeof hotbarAddAction | typeof hotbarRemoveAction | typeof hotbarRenameAction; +} + +interface SwitchToHotbarOption { + hotbar: Hotbar; +} + +type HotbarSwitchOption = SwitchToHotbarOption | HotbarSwitchActionOption; + +function getHotbarSwitchOptions(hotbars: Hotbar[]): HotbarSwitchOption[] { return [ - ...hotbars, - hotbarAddAction, + ...hotbars.map(hotbar => ({ hotbar })), + { action: hotbarAddAction }, ...ignoreIf(hotbars.length > 1, [ - hotbarRemoveAction, - ] as const), - hotbarRenameAction, + { action: hotbarRemoveAction } as const, + ]), + { action: hotbarRenameAction }, ]; } +function isActionOption(option: HotbarSwitchOption): option is HotbarSwitchActionOption { + return Boolean((option as HotbarSwitchActionOption).action); +} + const NonInjectedHotbarSwitchCommand = observer(({ hotbarStore, commandOverlay, @@ -47,40 +61,45 @@ const NonInjectedHotbarSwitchCommand = observer(({