Skip to content

Commit 9e25efb

Browse files
authored
fix(material/table): return undefined sort and paginator (#31593)
The initial value for `sort` and `paginator` is `undefined` and since #31269 the setter accepts `undefined` too (typically from a signal child query). This change aligns the getter type with the real type and makes it symmetric with the setter.
1 parent 409948f commit 9e25efb

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

goldens/material/table/index.api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ export class MatTableDataSource<T, P extends MatPaginator = MatPaginator> extend
186186
filterPredicate: (data: T, filter: string) => boolean;
187187
_orderData(data: T[]): T[];
188188
_pageData(data: T[]): T[];
189-
get paginator(): P | null;
189+
get paginator(): P | null | undefined;
190190
set paginator(paginator: P | null | undefined);
191191
_renderChangesSubscription: Subscription | null;
192-
get sort(): MatSort | null;
192+
get sort(): MatSort | null | undefined;
193193
set sort(sort: MatSort | null | undefined);
194194
sortData: (data: T[], sort: MatSort) => T[];
195195
sortingDataAccessor: (data: T, sortHeaderId: string) => string | number;

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,16 @@ export class MatTableDataSource<T, P extends MatPaginator = MatPaginator> extend
103103
* Instance of the MatSort directive used by the table to control its sorting. Sort changes
104104
* emitted by the MatSort will trigger an update to the table's rendered data.
105105
*/
106-
get sort(): MatSort | null {
106+
get sort(): MatSort | null | undefined {
107107
return this._sort;
108108
}
109109

110110
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;
111+
this._sort = sort;
114112
this._updateChangeSubscription();
115113
}
116114

117-
private _sort: MatSort | null;
115+
private _sort: MatSort | null | undefined;
118116

119117
/**
120118
* Instance of the paginator component used by the table to control what page of the data is
@@ -126,18 +124,16 @@ export class MatTableDataSource<T, P extends MatPaginator = MatPaginator> extend
126124
* e.g. `[pageLength]=100` or `[pageIndex]=1`, then be sure that the paginator's view has been
127125
* initialized before assigning it to this data source.
128126
*/
129-
get paginator(): P | null {
127+
get paginator(): P | null | undefined {
130128
return this._paginator;
131129
}
132130

133131
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;
132+
this._paginator = paginator;
137133
this._updateChangeSubscription();
138134
}
139135

140-
private _paginator: P | null;
136+
private _paginator: P | null | undefined;
141137

142138
/**
143139
* Data accessor function that is used for accessing data properties for sorting through

0 commit comments

Comments
 (0)