Skip to content

Commit 962e303

Browse files
crisbetoandrewseguin
authored andcommitted
refactor: remove explicit generics in rxjs usages (#15431)
Removes all the places where we set generic explicitly for rxjs objects, in order to avoid potential issues with rxjs 6.4. Fixes #15307.
1 parent 66dc61f commit 962e303

File tree

13 files changed

+26
-22
lines changed

13 files changed

+26
-22
lines changed

src/cdk-experimental/dialog/dialog.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ export class Dialog implements OnDestroy {
5656
_afterAllClosedBase = new Subject<void>();
5757

5858
// TODO(jelbourn): tighten the type on the right-hand side of this expression.
59-
afterAllClosed: Observable<void> = defer<any>(() => this.openDialogs.length ?
60-
this._afterAllClosed : this._afterAllClosed.pipe(startWith<void>(undefined))) as any;
59+
afterAllClosed: Observable<void> = defer(() => this.openDialogs.length ?
60+
this._afterAllClosed : this._afterAllClosed.pipe(startWith(undefined)));
6161

6262
/** Stream that emits when a dialog is opened. */
6363
get afterOpened(): Subject<DialogRef<any>> {

src/cdk/scrolling/viewport-ruler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class ViewportRuler implements OnDestroy {
3838
constructor(private _platform: Platform, ngZone: NgZone) {
3939
ngZone.runOutsideAngular(() => {
4040
this._change = _platform.isBrowser ?
41-
merge<Event>(fromEvent(window, 'resize'), fromEvent(window, 'orientationchange')) :
41+
merge(fromEvent(window, 'resize'), fromEvent(window, 'orientationchange')) :
4242
observableOf();
4343

4444
// Note that we need to do the subscription inside `runOutsideAngular`

src/cdk/scrolling/virtual-for-of.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export class CdkVirtualForOf<T> implements CollectionViewer, DoCheck, OnDestroy
131131
dataStream: Observable<T[] | ReadonlyArray<T>> = this._dataSourceChanges
132132
.pipe(
133133
// Start off with null `DataSource`.
134-
startWith<DataSource<T>>(null!),
134+
startWith(null!),
135135
// Bundle up the previous and current data sources so we can work with both.
136136
pairwise(),
137137
// Use `_changeDataSource` to disconnect from the previous data source and connect to the

src/cdk/scrolling/virtual-scroll-viewport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export class CdkVirtualScrollViewport extends CdkScrollable implements OnInit, O
161161
this.elementScrolled()
162162
.pipe(
163163
// Start off with a fake scroll event so we properly detect our initial position.
164-
startWith<Event | null>(null!),
164+
startWith(null!),
165165
// Collect multiple events into one until the next animation frame. This way if
166166
// there are multiple scroll events in the same frame we only need to recheck
167167
// our layout once.

src/lib/autocomplete/autocomplete-trigger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,8 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
323323
}
324324

325325
return merge(
326-
fromEvent<MouseEvent>(this._document, 'click'),
327-
fromEvent<TouchEvent>(this._document, 'touchend')
326+
fromEvent(this._document, 'click') as Observable<MouseEvent>,
327+
fromEvent(this._document, 'touchend') as Observable<TouchEvent>
328328
)
329329
.pipe(filter(event => {
330330
const clickTarget = event.target as HTMLElement;

src/lib/core/line/line.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class MatLine {}
3434
export function setLines(lines: QueryList<MatLine>, element: ElementRef<HTMLElement>) {
3535
// Note: doesn't need to unsubscribe, because `changes`
3636
// gets completed by Angular when the view is destroyed.
37-
lines.changes.pipe(startWith<QueryList<MatLine>>(lines)).subscribe(({length}) => {
37+
lines.changes.pipe(startWith(lines)).subscribe(({length}) => {
3838
setClass(element, 'mat-2-line', false);
3939
setClass(element, 'mat-3-line', false);
4040
setClass(element, 'mat-multi-line', false);

src/lib/dialog/dialog.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ export class MatDialog implements OnDestroy {
103103
* Stream that emits when all open dialog have finished closing.
104104
* Will emit on subscribe if there are no open dialogs to begin with.
105105
*/
106-
readonly afterAllClosed: Observable<void> = defer<any>(() => this.openDialogs.length ?
106+
readonly afterAllClosed: Observable<void> = defer(() => this.openDialogs.length ?
107107
this._afterAllClosed :
108-
this._afterAllClosed.pipe(startWith(undefined as void))) as Observable<any>;
108+
this._afterAllClosed.pipe(startWith(undefined))) as Observable<any>;
109109

110110
constructor(
111111
private _overlay: Overlay,

src/lib/expansion/expansion-panel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export class MatExpansionPanel extends CdkAccordionItem implements AfterContentI
194194
if (this._lazyContent) {
195195
// Render the content as soon as the panel becomes open.
196196
this.opened.pipe(
197-
startWith<void>(null!),
197+
startWith(null!),
198198
filter(() => this.expanded && !this._portal),
199199
take(1)
200200
).subscribe(() => {

src/lib/form-field/form-field.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ export class MatFormField extends _MatFormFieldMixinBase
287287
}
288288

289289
// Subscribe to changes in the child control state in order to update the form field UI.
290-
control.stateChanges.pipe(startWith<void>(null!)).subscribe(() => {
290+
control.stateChanges.pipe(startWith(null!)).subscribe(() => {
291291
this._validatePlaceholders();
292292
this._syncDescribedByIds();
293293
this._changeDetectorRef.markForCheck();

src/lib/progress-bar/progress-bar.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
InjectionToken,
2323
inject,
2424
} from '@angular/core';
25-
import {fromEvent, Subscription} from 'rxjs';
25+
import {fromEvent, Subscription, Observable} from 'rxjs';
2626
import {filter} from 'rxjs/operators';
2727
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
2828
import {CanColor, CanColorCtor, mixinColor} from '@angular/material/core';
@@ -195,11 +195,12 @@ export class MatProgressBar extends _MatProgressBarMixinBase implements CanColor
195195
// Run outside angular so change detection didn't get triggered on every transition end
196196
// instead only on the animation that we care about (primary value bar's transitionend)
197197
this._ngZone.runOutsideAngular((() => {
198+
const element = this._primaryValueBar.nativeElement;
199+
198200
this._animationEndSubscription =
199-
fromEvent<TransitionEvent>(this._primaryValueBar.nativeElement, 'transitionend')
200-
.pipe(filter(((e: TransitionEvent) =>
201-
e.target === this._primaryValueBar.nativeElement)))
202-
.subscribe(_ => this._ngZone.run(() => this.emitAnimationEnd()));
201+
(fromEvent(element, 'transitionend') as Observable<TransitionEvent>)
202+
.pipe(filter(((e: TransitionEvent) => e.target === element)))
203+
.subscribe(() => this._ngZone.run(() => this.emitAnimationEnd()));
203204
}));
204205
}
205206
}

src/lib/sidenav/drawer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ export class MatDrawer implements AfterContentInit, AfterContentChecked, OnDestr
262262
* and we don't have close disabled.
263263
*/
264264
this._ngZone.runOutsideAngular(() => {
265-
fromEvent<KeyboardEvent>(this._elementRef.nativeElement, 'keydown').pipe(
265+
(fromEvent(this._elementRef.nativeElement, 'keydown') as Observable<KeyboardEvent>).pipe(
266266
filter(event => event.keyCode === ESCAPE && !this.disableClose),
267267
takeUntil(this._destroyed)
268268
).subscribe(event => this._ngZone.run(() => {

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,14 @@ export class MatTableDataSource<T> extends DataSource<T> {
212212
// pipeline can progress to the next step. Note that the value from these streams are not used,
213213
// they purely act as a signal to progress in the pipeline.
214214
const sortChange: Observable<Sort|null|void> = this._sort ?
215-
merge<Sort|void>(this._sort.sortChange, this._sort.initialized) :
215+
merge(this._sort.sortChange, this._sort.initialized) as Observable<Sort|void> :
216216
observableOf(null);
217217
const pageChange: Observable<PageEvent|null|void> = this._paginator ?
218-
merge<PageEvent|void>(
219-
this._paginator.page, this._internalPageChanges, this._paginator.initialized) :
218+
merge(
219+
this._paginator.page,
220+
this._internalPageChanges,
221+
this._paginator.initialized
222+
) as Observable<PageEvent|void> :
220223
observableOf(null);
221224
const dataStream = this._data;
222225
// Watch for base data or filter changes to provide a filtered set of data.

src/material-examples/autocomplete-display/autocomplete-display-example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class AutocompleteDisplayExample implements OnInit {
2727
ngOnInit() {
2828
this.filteredOptions = this.myControl.valueChanges
2929
.pipe(
30-
startWith<string | User>(''),
30+
startWith(''),
3131
map(value => typeof value === 'string' ? value : value.name),
3232
map(name => name ? this._filter(name) : this.options.slice())
3333
);

0 commit comments

Comments
 (0)