Skip to content

Commit ff23527

Browse files
crisbetovivian-hu-zz
authored andcommitted
refactor(table): allow readonly array in data source input (#13137)
Adds `ReadonlyArray` and `Observable<ReadonlyArray>` to the list of accepted types for the `CdkTable.dataSource` input. Fixes #13126.
1 parent f5dd24a commit ff23527

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/cdk/table/table.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ export interface RowOutlet {
6464
viewContainer: ViewContainerRef;
6565
}
6666

67+
/**
68+
* Union of the types that can be set as the data source for a `CdkTable`.
69+
* @docs-private
70+
*/
71+
type CdkTableDataSourceInput<T> = DataSource<T> | Observable<ReadonlyArray<T> | T[]> |
72+
ReadonlyArray<T> | T[];
73+
6774
/**
6875
* Provides a handle for the table to grab the view container's ng-container to insert data rows.
6976
* @docs-private
@@ -310,13 +317,13 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
310317
* subscriptions registered during the connect process).
311318
*/
312319
@Input()
313-
get dataSource(): DataSource<T> | Observable<T[]> | T[] { return this._dataSource; }
314-
set dataSource(dataSource: DataSource<T> | Observable<T[]> | T[]) {
320+
get dataSource(): CdkTableDataSourceInput<T> { return this._dataSource; }
321+
set dataSource(dataSource: CdkTableDataSourceInput<T>) {
315322
if (this._dataSource !== dataSource) {
316323
this._switchDataSource(dataSource);
317324
}
318325
}
319-
private _dataSource: DataSource<T> | Observable<T[]> | T[] | T[];
326+
private _dataSource: CdkTableDataSourceInput<T>;
320327

321328
/**
322329
* Whether to allow multiple rows per data object by evaluating which rows evaluate their 'when'
@@ -759,7 +766,7 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
759766
* render change subscription if one exists. If the data source is null, interpret this by
760767
* clearing the row outlet. Otherwise start listening for new data.
761768
*/
762-
private _switchDataSource(dataSource: DataSource<T> | Observable<T[]> | T[]) {
769+
private _switchDataSource(dataSource: CdkTableDataSourceInput<T>) {
763770
this._data = [];
764771

765772
if (this.dataSource instanceof DataSource) {

0 commit comments

Comments
 (0)