refactor(router): compatibility with typescript strict flag (#30993)

As part of FW-1265, the `@angular/router` package is made compatible
with the TypeScript `--strict` flag. Read more about the strict flag [here](https://www.typescriptlang.org/docs/handbook/compiler-options.html)

PR Close #30993
This commit is contained in:
Paul Gschwendtner 2019-06-13 21:15:45 +02:00 committed by Miško Hevery
parent 18f0c2f1d4
commit ce9d0de840
4 changed files with 12 additions and 9 deletions

View File

@ -11,7 +11,7 @@ import {Attribute, Directive, ElementRef, HostBinding, HostListener, Input, OnCh
import {Subscription} from 'rxjs';
import {QueryParamsHandling} from '../config';
import {NavigationEnd, RouterEvent} from '../events';
import {Event, NavigationEnd} from '../events';
import {Router} from '../router';
import {ActivatedRoute} from '../router_state';
import {UrlTree} from '../url_tree';
@ -220,7 +220,7 @@ export class RouterLinkWithHref implements OnChanges, OnDestroy {
constructor(
private router: Router, private route: ActivatedRoute,
private locationStrategy: LocationStrategy) {
this.subscription = router.events.subscribe((s: RouterEvent) => {
this.subscription = router.events.subscribe((s: Event) => {
if (s instanceof NavigationEnd) {
this.updateTargetUrlAndHref();
}

View File

@ -9,7 +9,7 @@
import {AfterContentInit, ContentChildren, Directive, ElementRef, Input, OnChanges, OnDestroy, Optional, QueryList, Renderer2, SimpleChanges} from '@angular/core';
import {Subscription} from 'rxjs';
import {NavigationEnd, RouterEvent} from '../events';
import {Event, NavigationEnd} from '../events';
import {Router} from '../router';
import {RouterLink, RouterLinkWithHref} from './router_link';
@ -95,7 +95,7 @@ export class RouterLinkActive implements OnChanges,
private router: Router, private element: ElementRef, private renderer: Renderer2,
@Optional() private link?: RouterLink,
@Optional() private linkWithHref?: RouterLinkWithHref) {
this.subscription = router.events.subscribe((s: RouterEvent) => {
this.subscription = router.events.subscribe((s: Event) => {
if (s instanceof NavigationEnd) {
this.update();
}

View File

@ -16,7 +16,7 @@ import {Route, Routes} from './config';
import {RouterLink, RouterLinkWithHref} from './directives/router_link';
import {RouterLinkActive} from './directives/router_link_active';
import {RouterOutlet} from './directives/router_outlet';
import {RouterEvent} from './events';
import {Event} from './events';
import {RouteReuseStrategy} from './route_reuse_strategy';
import {ErrorHandler, Router} from './router';
import {ROUTES} from './router_config_loader';
@ -444,7 +444,7 @@ export function setupRouter(
if (opts.enableTracing) {
const dom = getDOM();
router.events.subscribe((e: RouterEvent) => {
router.events.subscribe((e: Event) => {
dom.logGroup(`Router Event: ${(<any>e.constructor).name}`);
dom.log(e.toString());
dom.log(e);

View File

@ -88,11 +88,14 @@ export function waitForMap<A, B>(
}
});
// Closure compiler has problem with using spread operator here. So just using Array.concat.
return of .apply(null, waitHead.concat(waitTail)).pipe(concatAll(), lastValue(), map(() => res));
// Closure compiler has problem with using spread operator here. So we use "Array.concat".
// Note that we also need to cast the new promise because TypeScript cannot infer the type
// when calling the "of" function through "Function.apply"
return (of .apply(null, waitHead.concat(waitTail)) as Observable<Observable<B>>)
.pipe(concatAll(), lastValue(), map(() => res));
}
export function wrapIntoObservable<T>(value: T | NgModuleFactory<T>| Promise<T>| Observable<T>) {
export function wrapIntoObservable<T>(value: T | Promise<T>| Observable<T>): Observable<T> {
if (isObservable(value)) {
return value;
}