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
This commit is contained in:
aschaap 2021-04-11 13:26:57 -04:00 committed by Zach Arend
parent 3a61bb82b3
commit 5e8dcfd641
1 changed files with 1 additions and 1 deletions

View File

@ -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);
}