fix(router): update type for routerLink to include null and undefined (#37018)
PR #13380 added support for `null` and `undefined` but the type on the parameter was not updated. This would result in a compilation error if `fullTemplateTypeCheck` is enabled. Fixes #36544 PR Close #37018
This commit is contained in:
parent
87f951c5c1
commit
ef9f8df9ed
4
goldens/public-api/router/router.d.ts
vendored
4
goldens/public-api/router/router.d.ts
vendored
@ -380,7 +380,7 @@ export declare class RouterLink {
|
|||||||
};
|
};
|
||||||
queryParamsHandling: QueryParamsHandling;
|
queryParamsHandling: QueryParamsHandling;
|
||||||
replaceUrl: boolean;
|
replaceUrl: boolean;
|
||||||
set routerLink(commands: any[] | string);
|
set routerLink(commands: any[] | string | null | undefined);
|
||||||
skipLocationChange: boolean;
|
skipLocationChange: boolean;
|
||||||
state?: {
|
state?: {
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
@ -414,7 +414,7 @@ export declare class RouterLinkWithHref implements OnChanges, OnDestroy {
|
|||||||
};
|
};
|
||||||
queryParamsHandling: QueryParamsHandling;
|
queryParamsHandling: QueryParamsHandling;
|
||||||
replaceUrl: boolean;
|
replaceUrl: boolean;
|
||||||
set routerLink(commands: any[] | string);
|
set routerLink(commands: any[] | string | null | undefined);
|
||||||
skipLocationChange: boolean;
|
skipLocationChange: boolean;
|
||||||
state?: {
|
state?: {
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
|
@ -139,7 +139,7 @@ export class RouterLink {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
set routerLink(commands: any[]|string) {
|
set routerLink(commands: any[]|string|null|undefined) {
|
||||||
if (commands != null) {
|
if (commands != null) {
|
||||||
this.commands = Array.isArray(commands) ? commands : [commands];
|
this.commands = Array.isArray(commands) ? commands : [commands];
|
||||||
} else {
|
} else {
|
||||||
@ -229,7 +229,7 @@ export class RouterLinkWithHref implements OnChanges, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
set routerLink(commands: any[]|string) {
|
set routerLink(commands: any[]|string|null|undefined) {
|
||||||
if (commands != null) {
|
if (commands != null) {
|
||||||
this.commands = Array.isArray(commands) ? commands : [commands];
|
this.commands = Array.isArray(commands) ? commands : [commands];
|
||||||
} else {
|
} else {
|
||||||
|
@ -1968,11 +1968,15 @@ describe('Integration', () => {
|
|||||||
expect(native.getAttribute('href')).toEqual('/home');
|
expect(native.getAttribute('href')).toEqual('/home');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should not throw when commands is null', fakeAsync(() => {
|
it('should not throw when commands is null or undefined', fakeAsync(() => {
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'someCmp',
|
selector: 'someCmp',
|
||||||
template:
|
template: `<router-outlet></router-outlet>
|
||||||
`<router-outlet></router-outlet><a [routerLink]="null">Link</a><button [routerLink]="null">Button</button>`
|
<a [routerLink]="null">Link</a>
|
||||||
|
<button [routerLink]="null">Button</button>
|
||||||
|
<a [routerLink]="undefined">Link</a>
|
||||||
|
<button [routerLink]="undefined">Button</button>
|
||||||
|
`
|
||||||
})
|
})
|
||||||
class CmpWithLink {
|
class CmpWithLink {
|
||||||
}
|
}
|
||||||
@ -1982,10 +1986,12 @@ describe('Integration', () => {
|
|||||||
|
|
||||||
let fixture: ComponentFixture<CmpWithLink> = createRoot(router, CmpWithLink);
|
let fixture: ComponentFixture<CmpWithLink> = createRoot(router, CmpWithLink);
|
||||||
router.resetConfig([{path: 'home', component: SimpleCmp}]);
|
router.resetConfig([{path: 'home', component: SimpleCmp}]);
|
||||||
const anchor = fixture.nativeElement.querySelector('a');
|
const anchors = fixture.nativeElement.querySelectorAll('a');
|
||||||
const button = fixture.nativeElement.querySelector('button');
|
const buttons = fixture.nativeElement.querySelectorAll('button');
|
||||||
expect(() => anchor.click()).not.toThrow();
|
expect(() => anchors[0].click()).not.toThrow();
|
||||||
expect(() => button.click()).not.toThrow();
|
expect(() => anchors[1].click()).not.toThrow();
|
||||||
|
expect(() => buttons[0].click()).not.toThrow();
|
||||||
|
expect(() => buttons[1].click()).not.toThrow();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should update hrefs when query params or fragment change', fakeAsync(() => {
|
it('should update hrefs when query params or fragment change', fakeAsync(() => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user