Skip to content

Commit fb4d280

Browse files
committed
refactor(table): Require T to be object | ArrayLike
1 parent 1f6504b commit fb4d280

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ const MAX_SAFE_INTEGER = 9007199254740991;
4040
* interactions. If your app needs to support more advanced use cases, consider implementing your
4141
* own `DataSource`.
4242
*/
43-
export class MatTableDataSource<T, P extends MatPaginator = MatPaginator> extends DataSource<T> {
43+
export class MatTableDataSource<
44+
T extends object | ArrayLike<unknown>,
45+
P extends MatPaginator = MatPaginator,
46+
> extends DataSource<T> {
4447
/** Stream that emits when a new data array is set on the data source. */
4548
private readonly _data: BehaviorSubject<T[]>;
4649

@@ -229,16 +232,10 @@ export class MatTableDataSource<T, P extends MatPaginator = MatPaginator> extend
229232
* @returns Whether the filter matches against the data
230233
*/
231234
filterPredicate: (data: T, filter: string) => boolean = (data: T, filter: string): boolean => {
232-
if ((typeof ngDevMode === 'undefined' || ngDevMode) && typeof data !== 'object') {
233-
throw new Error('Default implementation of filterPredicate requires data to be object.');
234-
}
235-
236235
// Transform the filter by converting it to lowercase and removing whitespace.
237236
const transformedFilter = filter.trim().toLowerCase();
238237
// Loops over the values in the array and returns true if any of them match the filter string
239-
return Object.values(data as object).some(value =>
240-
`${value}`.toLowerCase().includes(transformedFilter),
241-
);
238+
return Object.values(data).some(value => `${value}`.toLowerCase().includes(transformedFilter));
242239
};
243240

244241
constructor(initialData: T[] = []) {

0 commit comments

Comments
 (0)