Skip to content

Commit 9627c29

Browse files
authored
feat(material/table): accept undefined sort and paginator (#31269)
Extend types of the sort and paginator setter to include undefined to avoid `?? null` when using singals (e.g. `viewChild`).
1 parent 0131bce commit 9627c29

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

goldens/material/table/index.api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,10 @@ export class MatTableDataSource<T, P extends MatPaginator = MatPaginator> extend
187187
_orderData(data: T[]): T[];
188188
_pageData(data: T[]): T[];
189189
get paginator(): P | null;
190-
set paginator(paginator: P | null);
190+
set paginator(paginator: P | null | undefined);
191191
_renderChangesSubscription: Subscription | null;
192192
get sort(): MatSort | null;
193-
set sort(sort: MatSort | null);
193+
set sort(sort: MatSort | null | undefined);
194194
sortData: (data: T[], sort: MatSort) => T[];
195195
sortingDataAccessor: (data: T, sortHeaderId: string) => string | number;
196196
_updateChangeSubscription(): void;

src/material/table/table-data-source.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ export class MatTableDataSource<T, P extends MatPaginator = MatPaginator> extend
107107
return this._sort;
108108
}
109109

110-
set sort(sort: MatSort | null) {
111-
this._sort = sort;
110+
set sort(sort: MatSort | null | undefined) {
111+
// Treat undefined like the initial this._sort value.
112+
// Note that the API can be changed in a breaking change to fix the cast.
113+
this._sort = sort as MatSort | null;
112114
this._updateChangeSubscription();
113115
}
114116

@@ -128,8 +130,10 @@ export class MatTableDataSource<T, P extends MatPaginator = MatPaginator> extend
128130
return this._paginator;
129131
}
130132

131-
set paginator(paginator: P | null) {
132-
this._paginator = paginator;
133+
set paginator(paginator: P | null | undefined) {
134+
// Treat undefined like the initial this._paginator value.
135+
// Note that the API can be changed in a breaking change to fix the cast.
136+
this._paginator = paginator as P | null;
133137
this._updateChangeSubscription();
134138
}
135139

0 commit comments

Comments
 (0)