From 4795c5e7d8bba2ec818fa978ec208488d64504c6 Mon Sep 17 00:00:00 2001 From: aschaap Date: Sun, 11 Apr 2021 13:26:57 -0400 Subject: [PATCH] docs(docs-infra): fix (+) not accepting null error by using `Number` instead (#41570) Fix unexpected error when following the tutorial (when going through it with stricter type checking enforced). While (+) converts a string to an integer, it does not account for the possibility that `this.route.snapshot.paramMap.get('id')` could return null (type: string | null). Since this null case is not a practical outcome, it is a matter of types; switching from (+) to the `Number` function eliminates this issue, making the tutorial more robust. PR Close #41570 --- .../toh-pt5/src/app/hero-detail/hero-detail.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aio/content/examples/toh-pt5/src/app/hero-detail/hero-detail.component.ts b/aio/content/examples/toh-pt5/src/app/hero-detail/hero-detail.component.ts index 362230dca7b..dc6439a4bd6 100644 --- a/aio/content/examples/toh-pt5/src/app/hero-detail/hero-detail.component.ts +++ b/aio/content/examples/toh-pt5/src/app/hero-detail/hero-detail.component.ts @@ -33,7 +33,7 @@ export class HeroDetailComponent implements OnInit { } getHero(): void { - const id = +this.route.snapshot.paramMap.get('id'); + const id = Number(this.route.snapshot.paramMap.get('id')); this.heroService.getHero(id) .subscribe(hero => this.hero = hero); }