Skip to content

Commit d0ff86a

Browse files
committed
change instanceof
1 parent 7056d38 commit d0ff86a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/cdk/tree/tree.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ export class CdkTree<T> implements CollectionViewer, OnInit, OnDestroy {
123123
this._onDestroy.next();
124124
this._onDestroy.complete();
125125

126-
if (this.dataSource instanceof DataSource) {
127-
this.dataSource.disconnect(this);
126+
if (this._dataSource && typeof (this._dataSource as DataSource<T>).disconnect === 'function') {
127+
(this.dataSource as DataSource<T>).disconnect(this);
128128
}
129129

130130
if (this._dataSubscription) {
@@ -157,8 +157,8 @@ export class CdkTree<T> implements CollectionViewer, OnInit, OnDestroy {
157157
private _switchDataSource(dataSource: DataSource<T> | Observable<T[]> | T[]) {
158158
this._data = new Array<T>();
159159

160-
if (this.dataSource instanceof DataSource) {
161-
this.dataSource.disconnect(this);
160+
if (this._dataSource && typeof (this._dataSource as DataSource<T>).disconnect === 'function') {
161+
(this.dataSource as DataSource<T>).disconnect(this);
162162
}
163163

164164
if (this._dataSubscription) {
@@ -183,7 +183,7 @@ export class CdkTree<T> implements CollectionViewer, OnInit, OnDestroy {
183183

184184
// Cannot use `instanceof DataSource` since the data source could be a literal with
185185
// `connect` function and may not extends DataSource.
186-
if ((this._dataSource as DataSource<T>).connect instanceof Function) {
186+
if (typeof (this._dataSource as DataSource<T>).connect === 'function') {
187187
dataStream = (this._dataSource as DataSource<T>).connect(this);
188188
} else if (this._dataSource instanceof Observable) {
189189
dataStream = this._dataSource;

0 commit comments

Comments
 (0)