refactor(router): remove non-null assertions (#48244)

As part of #24571, removing non-null assertions (where appropriate)

PR Close #48244
This commit is contained in:
Matthieu Riegler
2022-11-27 18:09:40 +01:00
committed by Andrew Scott
parent afc668acd5
commit dac5860a47
4 changed files with 17 additions and 29 deletions
+4 -10
View File
@@ -19,10 +19,8 @@ export const ROUTER_SCROLLER = new InjectionToken<RouterScroller>('');
@Injectable()
export class RouterScroller implements OnDestroy {
// TODO(issue/24571): remove '!'.
private routerEventsSubscription!: Unsubscribable;
// TODO(issue/24571): remove '!'.
private scrollEventsSubscription!: Unsubscribable;
private routerEventsSubscription?: Unsubscribable;
private scrollEventsSubscription?: Unsubscribable;
private lastId = 0;
private lastSource: 'imperative'|'popstate'|'hashchange'|undefined = 'imperative';
@@ -105,11 +103,7 @@ export class RouterScroller implements OnDestroy {
/** @nodoc */
ngOnDestroy() {
if (this.routerEventsSubscription) {
this.routerEventsSubscription.unsubscribe();
}
if (this.scrollEventsSubscription) {
this.scrollEventsSubscription.unsubscribe();
}
this.routerEventsSubscription?.unsubscribe();
this.scrollEventsSubscription?.unsubscribe();
}
}
+5 -9
View File
@@ -115,9 +115,9 @@ export class ActivatedRoute {
/** @internal */
_routerState!: RouterState;
/** @internal */
_paramMap!: Observable<ParamMap>;
_paramMap?: Observable<ParamMap>;
/** @internal */
_queryParamMap!: Observable<ParamMap>;
_queryParamMap?: Observable<ParamMap>;
/** An Observable of the resolved route title */
readonly title: Observable<string|undefined> =
@@ -288,17 +288,13 @@ export class ActivatedRouteSnapshot {
/** @internal */
_resolve: ResolveData;
/** @internal */
// TODO(issue/24571): remove '!'.
_resolvedData!: Data;
_resolvedData?: Data;
/** @internal */
// TODO(issue/24571): remove '!'.
_routerState!: RouterStateSnapshot;
/** @internal */
// TODO(issue/24571): remove '!'.
_paramMap!: ParamMap;
_paramMap?: ParamMap;
/** @internal */
// TODO(issue/24571): remove '!'.
_queryParamMap!: ParamMap;
_queryParamMap?: ParamMap;
/** The resolved route title */
get title(): string|undefined {
+2 -4
View File
@@ -189,8 +189,7 @@ function matrixParamsMatch(
*/
export class UrlTree {
/** @internal */
// TODO(issue/24571): remove '!'.
_queryParamMap!: ParamMap;
_queryParamMap?: ParamMap;
constructor(
/** The root segment group of the URL tree */
@@ -299,8 +298,7 @@ export class UrlSegmentGroup {
*/
export class UrlSegment {
/** @internal */
// TODO(issue/24571): remove '!'.
_parameterMap!: ParamMap;
_parameterMap?: ParamMap;
constructor(
/** The path part of a URL segment */
@@ -123,18 +123,18 @@ describe('Integration', () => {
`
})
class ComponentWithRouterLink {
// TODO(issue/24571): remove '!'.
@ViewChild(TemplateRef, {static: true}) templateRef!: TemplateRef<any>;
// TODO(issue/24571): remove '!'.
@ViewChild(TemplateRef, {static: true}) templateRef?: TemplateRef<any>;
@ViewChild('container', {read: ViewContainerRef, static: true})
container!: ViewContainerRef;
container?: ViewContainerRef;
addLink() {
this.container.createEmbeddedView(this.templateRef, {$implicit: '/simple'});
if (this.templateRef) {
this.container?.createEmbeddedView(this.templateRef, {$implicit: '/simple'});
}
}
removeLink() {
this.container.clear();
this.container?.clear();
}
}