From 044d96fdfdfc0f7abe077208fc9f7008223d8281 Mon Sep 17 00:00:00 2001 From: dario-piotrowicz Date: Thu, 11 Nov 2021 22:25:25 +0000 Subject: [PATCH] refactor(multiple): add non-null assertions to first and last Angular's QueryList first and last can actually be `undefined`, although this is not reflected by their type (this is a current bug in Angular: https://github.com/angular/angular/issues/42563) this commit adds non-null assertions to first and last references within the codebase in preparation for solving the Angular bug without causing too many breaking changes For more information see: https://github.com/angular/angular/pull/43604 --- src/cdk/tree/tree.ts | 2 +- src/material-experimental/mdc-slider/slider.ts | 4 ++-- src/material/menu/menu.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cdk/tree/tree.ts b/src/cdk/tree/tree.ts index 16a6c0058bd5..96ad12200f4e 100644 --- a/src/cdk/tree/tree.ts +++ b/src/cdk/tree/tree.ts @@ -262,7 +262,7 @@ export class CdkTree implements AfterContentChecked, CollectionViewer, */ _getNodeDef(data: T, i: number): CdkTreeNodeDef { if (this._nodeDefs.length === 1) { - return this._nodeDefs.first; + return this._nodeDefs.first!; } const nodeDef = diff --git a/src/material-experimental/mdc-slider/slider.ts b/src/material-experimental/mdc-slider/slider.ts index 20ca4d1d6db8..28a1c438e4f8 100644 --- a/src/material-experimental/mdc-slider/slider.ts +++ b/src/material-experimental/mdc-slider/slider.ts @@ -847,7 +847,7 @@ export class MatSlider /** Gets the slider thumb input of the given thumb position. */ _getInput(thumbPosition: Thumb): MatSliderThumb { - return thumbPosition === Thumb.END ? this._inputs.last : this._inputs.first; + return thumbPosition === Thumb.END ? this._inputs.last! : this._inputs.first!; } /** Gets the slider thumb HTML input element of the given thumb position. */ @@ -856,7 +856,7 @@ export class MatSlider } _getThumb(thumbPosition: Thumb): MatSliderVisualThumb { - return thumbPosition === Thumb.END ? this._thumbs.last : this._thumbs.first; + return thumbPosition === Thumb.END ? this._thumbs.last! : this._thumbs.first!; } /** Gets the slider thumb HTML element of the given thumb position. */ diff --git a/src/material/menu/menu.ts b/src/material/menu/menu.ts index d65c6e6ace05..11f403d42166 100644 --- a/src/material/menu/menu.ts +++ b/src/material/menu/menu.ts @@ -386,7 +386,7 @@ export class _MatMenuBase // Move focus to the menu panel so keyboard events like Escape still work. Also this will // give _some_ feedback to screen readers. if (!manager.activeItem && this._directDescendantItems.length) { - let element = this._directDescendantItems.first._getHostElement().parentElement; + let element = this._directDescendantItems.first!._getHostElement().parentElement; // Because the `mat-menu` is at the DOM insertion point, not inside the overlay, we don't // have a nice way of getting a hold of the menu panel. We can't use a `ViewChild` either