From 62d75d0d4be55f5e9dbc1db02ea38f3f9aa1445c Mon Sep 17 00:00:00 2001 From: Rafal Slawik Date: Sat, 31 May 2025 16:32:27 +0000 Subject: [PATCH] feat(material/table): accept undefined sort and paginator Extend types of the sort and paginator setter to include undefined to avoid `?? null` when using singals (e.g. `viewChild`). --- src/material/table/table-data-source.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/material/table/table-data-source.ts b/src/material/table/table-data-source.ts index c19e8e1e921a..5052a6b8356b 100644 --- a/src/material/table/table-data-source.ts +++ b/src/material/table/table-data-source.ts @@ -107,8 +107,10 @@ export class MatTableDataSource extend return this._sort; } - set sort(sort: MatSort | null) { - this._sort = sort; + set sort(sort: MatSort | null | undefined) { + // Treat undefined like the initial this._sort value. + // Note that the API can be changed in a breaking change to fix the cast. + this._sort = sort as MatSort | null; this._updateChangeSubscription(); } @@ -128,8 +130,10 @@ export class MatTableDataSource extend return this._paginator; } - set paginator(paginator: P | null) { - this._paginator = paginator; + set paginator(paginator: P | null | undefined) { + // Treat undefined like the initial this._paginator value. + // Note that the API can be changed in a breaking change to fix the cast. + this._paginator = paginator as P | null; this._updateChangeSubscription(); }