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:
parent
3a61bb82b3
commit
5e8dcfd641
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue