From 31a959efe9fa4bad78f8cb2cec081b780173f281 Mon Sep 17 00:00:00 2001 From: Kerry Date: Thu, 16 Mar 2023 09:27:59 +1300 Subject: [PATCH] Apply `strictNullChecks` to `src/resizer/*` (#10378) --- src/resizer/distributors/collapse.ts | 6 +++--- src/resizer/distributors/percentage.ts | 4 ++-- src/resizer/item.ts | 14 +++++++++++--- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/resizer/distributors/collapse.ts b/src/resizer/distributors/collapse.ts index 96d355d326..507b62e903 100644 --- a/src/resizer/distributors/collapse.ts +++ b/src/resizer/distributors/collapse.ts @@ -21,7 +21,7 @@ import Sizer from "../sizer"; export interface ICollapseConfig extends IConfig { toggleSize: number; - onCollapsed?(collapsed: boolean, id: string, element: HTMLElement): void; + onCollapsed?(collapsed: boolean, id: string | null, element: HTMLElement): void; isItemCollapsed(element: HTMLElement): boolean; } @@ -45,7 +45,7 @@ export default class CollapseDistributor extends FixedDistributor { private advance(forwards: boolean): ResizeItem | undefined { // opposite direction from fromResizeHandle to get back to handle - let handle = this.reverse ? this.domNode.previousElementSibling : this.domNode.nextElementSibling; + let handle: Element | null | undefined = this.reverse + ? this.domNode.previousElementSibling + : this.domNode.nextElementSibling; const moveNext = forwards !== this.reverse; // xor // iterate at least once to avoid infinite loop do { if (moveNext) { - handle = handle.nextElementSibling; + handle = handle?.nextElementSibling; } else { - handle = handle.previousElementSibling; + handle = handle?.previousElementSibling; } } while (handle && !this.resizer.isResizeHandle(handle)); @@ -105,6 +107,9 @@ export default class ResizeItem { } public first(): ResizeItem | undefined { + if (!this.domNode.parentElement?.children) { + return; + } const firstHandle = Array.from(this.domNode.parentElement.children).find((el) => { return this.resizer.isResizeHandle(el); }); @@ -114,6 +119,9 @@ export default class ResizeItem { } public last(): ResizeItem | undefined { + if (!this.domNode.parentElement?.children) { + return; + } const lastHandle = Array.from(this.domNode.parentElement.children) .reverse() .find((el) => {