fix(router): Allow undefined inputs on routerLink (#39151)

This make it coherent with typing of Router.createUrlTree to which
those inputs are directly forwarded to. And hence it allow to pass
`undefined`, `null` or a value to the routerLink directive.

BREAKING CHANGE: in most cases this should not break, but if you were
accessing the values of `queryParams`, `fragment` or `queryParamsHandling`
you might need to relax the typing to also accept `undefined` and `null`.

Signed-off-by: Adrien Crivelli <adrien.crivelli@gmail.com>

PR Close #39151
This commit is contained in:
Adrien Crivelli 2020-10-07 13:13:36 +09:00 committed by atscott
parent 72f4497f11
commit b0b4953fd6
2 changed files with 13 additions and 22 deletions

View File

@ -376,13 +376,11 @@ export declare class RouterEvent {
} }
export declare class RouterLink implements OnChanges { export declare class RouterLink implements OnChanges {
fragment: string; fragment?: string;
preserveFragment: boolean; preserveFragment: boolean;
/** @deprecated */ set preserveQueryParams(value: boolean); /** @deprecated */ set preserveQueryParams(value: boolean);
queryParams: { queryParams?: Params | null;
[k: string]: any; queryParamsHandling?: QueryParamsHandling | null;
};
queryParamsHandling: QueryParamsHandling;
replaceUrl: boolean; replaceUrl: boolean;
set routerLink(commands: any[] | string | null | undefined); set routerLink(commands: any[] | string | null | undefined);
skipLocationChange: boolean; skipLocationChange: boolean;
@ -410,14 +408,12 @@ export declare class RouterLinkActive implements OnChanges, OnDestroy, AfterCont
} }
export declare class RouterLinkWithHref implements OnChanges, OnDestroy { export declare class RouterLinkWithHref implements OnChanges, OnDestroy {
fragment: string; fragment?: string;
href: string; href: string;
preserveFragment: boolean; preserveFragment: boolean;
/** @deprecated */ set preserveQueryParams(value: boolean); /** @deprecated */ set preserveQueryParams(value: boolean);
queryParams: { queryParams?: Params | null;
[k: string]: any; queryParamsHandling?: QueryParamsHandling | null;
};
queryParamsHandling: QueryParamsHandling;
replaceUrl: boolean; replaceUrl: boolean;
set routerLink(commands: any[] | string | null | undefined); set routerLink(commands: any[] | string | null | undefined);
skipLocationChange: boolean; skipLocationChange: boolean;

View File

@ -14,6 +14,7 @@ import {QueryParamsHandling} from '../config';
import {Event, NavigationEnd} from '../events'; import {Event, NavigationEnd} from '../events';
import {Router} from '../router'; import {Router} from '../router';
import {ActivatedRoute} from '../router_state'; import {ActivatedRoute} from '../router_state';
import {Params} from '../shared';
import {UrlTree} from '../url_tree'; import {UrlTree} from '../url_tree';
@ -122,24 +123,21 @@ export class RouterLink implements OnChanges {
* @see {@link UrlCreationOptions#queryParams UrlCreationOptions#queryParams} * @see {@link UrlCreationOptions#queryParams UrlCreationOptions#queryParams}
* @see {@link Router#createUrlTree Router#createUrlTree} * @see {@link Router#createUrlTree Router#createUrlTree}
*/ */
// TODO(issue/24571): remove '!'. @Input() queryParams?: Params|null;
@Input() queryParams!: {[k: string]: any};
/** /**
* Passed to {@link Router#createUrlTree Router#createUrlTree} as part of the * Passed to {@link Router#createUrlTree Router#createUrlTree} as part of the
* `UrlCreationOptions`. * `UrlCreationOptions`.
* @see {@link UrlCreationOptions#fragment UrlCreationOptions#fragment} * @see {@link UrlCreationOptions#fragment UrlCreationOptions#fragment}
* @see {@link Router#createUrlTree Router#createUrlTree} * @see {@link Router#createUrlTree Router#createUrlTree}
*/ */
// TODO(issue/24571): remove '!'. @Input() fragment?: string;
@Input() fragment!: string;
/** /**
* Passed to {@link Router#createUrlTree Router#createUrlTree} as part of the * Passed to {@link Router#createUrlTree Router#createUrlTree} as part of the
* `UrlCreationOptions`. * `UrlCreationOptions`.
* @see {@link UrlCreationOptions#queryParamsHandling UrlCreationOptions#queryParamsHandling} * @see {@link UrlCreationOptions#queryParamsHandling UrlCreationOptions#queryParamsHandling}
* @see {@link Router#createUrlTree Router#createUrlTree} * @see {@link Router#createUrlTree Router#createUrlTree}
*/ */
// TODO(issue/24571): remove '!'. @Input() queryParamsHandling?: QueryParamsHandling|null;
@Input() queryParamsHandling!: QueryParamsHandling;
/** /**
* Passed to {@link Router#createUrlTree Router#createUrlTree} as part of the * Passed to {@link Router#createUrlTree Router#createUrlTree} as part of the
* `UrlCreationOptions`. * `UrlCreationOptions`.
@ -264,24 +262,21 @@ export class RouterLinkWithHref implements OnChanges, OnDestroy {
* @see {@link UrlCreationOptions#queryParams UrlCreationOptions#queryParams} * @see {@link UrlCreationOptions#queryParams UrlCreationOptions#queryParams}
* @see {@link Router#createUrlTree Router#createUrlTree} * @see {@link Router#createUrlTree Router#createUrlTree}
*/ */
// TODO(issue/24571): remove '!'. @Input() queryParams?: Params|null;
@Input() queryParams!: {[k: string]: any};
/** /**
* Passed to {@link Router#createUrlTree Router#createUrlTree} as part of the * Passed to {@link Router#createUrlTree Router#createUrlTree} as part of the
* `UrlCreationOptions`. * `UrlCreationOptions`.
* @see {@link UrlCreationOptions#fragment UrlCreationOptions#fragment} * @see {@link UrlCreationOptions#fragment UrlCreationOptions#fragment}
* @see {@link Router#createUrlTree Router#createUrlTree} * @see {@link Router#createUrlTree Router#createUrlTree}
*/ */
// TODO(issue/24571): remove '!'. @Input() fragment?: string;
@Input() fragment!: string;
/** /**
* Passed to {@link Router#createUrlTree Router#createUrlTree} as part of the * Passed to {@link Router#createUrlTree Router#createUrlTree} as part of the
* `UrlCreationOptions`. * `UrlCreationOptions`.
* @see {@link UrlCreationOptions#queryParamsHandling UrlCreationOptions#queryParamsHandling} * @see {@link UrlCreationOptions#queryParamsHandling UrlCreationOptions#queryParamsHandling}
* @see {@link Router#createUrlTree Router#createUrlTree} * @see {@link Router#createUrlTree Router#createUrlTree}
*/ */
// TODO(issue/24571): remove '!'. @Input() queryParamsHandling?: QueryParamsHandling|null;
@Input() queryParamsHandling!: QueryParamsHandling;
/** /**
* Passed to {@link Router#createUrlTree Router#createUrlTree} as part of the * Passed to {@link Router#createUrlTree Router#createUrlTree} as part of the
* `UrlCreationOptions`. * `UrlCreationOptions`.