Skip to content

Commit 5138328

Browse files
refactor(multiple): add non-null assertions to first and last (#23958)
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: angular/angular#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: angular/angular#43604
1 parent bcb74f5 commit 5138328

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/cdk/tree/tree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ export class CdkTree<T, K = T> implements AfterContentChecked, CollectionViewer,
262262
*/
263263
_getNodeDef(data: T, i: number): CdkTreeNodeDef<T> {
264264
if (this._nodeDefs.length === 1) {
265-
return this._nodeDefs.first;
265+
return this._nodeDefs.first!;
266266
}
267267

268268
const nodeDef =

src/material-experimental/mdc-slider/slider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ export class MatSlider
847847

848848
/** Gets the slider thumb input of the given thumb position. */
849849
_getInput(thumbPosition: Thumb): MatSliderThumb {
850-
return thumbPosition === Thumb.END ? this._inputs.last : this._inputs.first;
850+
return thumbPosition === Thumb.END ? this._inputs.last! : this._inputs.first!;
851851
}
852852

853853
/** Gets the slider thumb HTML input element of the given thumb position. */
@@ -856,7 +856,7 @@ export class MatSlider
856856
}
857857

858858
_getThumb(thumbPosition: Thumb): MatSliderVisualThumb {
859-
return thumbPosition === Thumb.END ? this._thumbs.last : this._thumbs.first;
859+
return thumbPosition === Thumb.END ? this._thumbs.last! : this._thumbs.first!;
860860
}
861861

862862
/** Gets the slider thumb HTML element of the given thumb position. */

src/material/menu/menu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ export class _MatMenuBase
386386
// Move focus to the menu panel so keyboard events like Escape still work. Also this will
387387
// give _some_ feedback to screen readers.
388388
if (!manager.activeItem && this._directDescendantItems.length) {
389-
let element = this._directDescendantItems.first._getHostElement().parentElement;
389+
let element = this._directDescendantItems.first!._getHostElement().parentElement;
390390

391391
// Because the `mat-menu` is at the DOM insertion point, not inside the overlay, we don't
392392
// have a nice way of getting a hold of the menu panel. We can't use a `ViewChild` either

0 commit comments

Comments
 (0)