From 792f238d162bd59bae3a41eb9eb39e84a9dddcbf Mon Sep 17 00:00:00 2001 From: David Luzar Date: Tue, 19 Jul 2022 15:44:04 +0200 Subject: [PATCH] refactor: improve typing & check (#5415) --- src/actions/actionDuplicateSelection.tsx | 15 ++++++++------ src/actions/actionSelectAll.ts | 24 +++++++++++++--------- src/components/App.tsx | 26 +++++++++++++++--------- 3 files changed, 39 insertions(+), 26 deletions(-) diff --git a/src/actions/actionDuplicateSelection.tsx b/src/actions/actionDuplicateSelection.tsx index 2ef0d25c..d8702a76 100644 --- a/src/actions/actionDuplicateSelection.tsx +++ b/src/actions/actionDuplicateSelection.tsx @@ -128,12 +128,15 @@ const duplicateElements = ( { ...appState, selectedGroupIds: {}, - selectedElementIds: newElements.reduce((acc, element) => { - if (!isBoundToContainer(element)) { - acc[element.id] = true; - } - return acc; - }, {} as any), + selectedElementIds: newElements.reduce( + (acc: Record, element) => { + if (!isBoundToContainer(element)) { + acc[element.id] = true; + } + return acc; + }, + {}, + ), }, getNonDeletedElements(finalElements), ), diff --git a/src/actions/actionSelectAll.ts b/src/actions/actionSelectAll.ts index 09c08d72..8a6763a6 100644 --- a/src/actions/actionSelectAll.ts +++ b/src/actions/actionSelectAll.ts @@ -2,6 +2,7 @@ import { KEYS } from "../keys"; import { register } from "./register"; import { selectGroupsForSelectedElements } from "../groups"; import { getNonDeletedElements, isTextElement } from "../element"; +import { ExcalidrawElement } from "../element/types"; export const actionSelectAll = register({ name: "selectAll", @@ -15,16 +16,19 @@ export const actionSelectAll = register({ { ...appState, editingGroupId: null, - selectedElementIds: elements.reduce((map, element) => { - if ( - !element.isDeleted && - !(isTextElement(element) && element.containerId) && - element.locked === false - ) { - map[element.id] = true; - } - return map; - }, {} as any), + selectedElementIds: elements.reduce( + (map: Record, element) => { + if ( + !element.isDeleted && + !(isTextElement(element) && element.containerId) && + !element.locked + ) { + map[element.id] = true; + } + return map; + }, + {}, + ), }, getNonDeletedElements(elements), ), diff --git a/src/components/App.tsx b/src/components/App.tsx index 271f1ac4..7a9240e9 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -1540,12 +1540,15 @@ class App extends React.Component { this.state.isLibraryOpen && this.device.canDeviceFitSidebar ? this.state.isLibraryMenuDocked : false, - selectedElementIds: newElements.reduce((map, element) => { - if (!isBoundToContainer(element)) { - map[element.id] = true; - } - return map; - }, {} as any), + selectedElementIds: newElements.reduce( + (acc: Record, element) => { + if (!isBoundToContainer(element)) { + acc[element.id] = true; + } + return acc; + }, + {}, + ), selectedGroupIds: {}, }, this.scene.getNonDeletedElements(), @@ -4307,10 +4310,13 @@ class App extends React.Component { ...prevState, selectedElementIds: { ...prevState.selectedElementIds, - ...elementsWithinSelection.reduce((map, element) => { - map[element.id] = true; - return map; - }, {} as any), + ...elementsWithinSelection.reduce( + (acc: Record, element) => { + acc[element.id] = true; + return acc; + }, + {}, + ), ...(pointerDownState.hit.element ? { // if using ctrl/cmd, select the hitElement only if we