I have been following this particular tutorial
Check out the code snippet below
HTML
<li *ngFor="let hero of heroes" (click)="onSelect(hero.id)">
<span class="badge">{{hero.id}}</span> {{hero.name}}
</li>
TS file
selectedHero: Hero;
onSelect(hero: Hero): void {
console.log(hero); // outputs 11
console.log(typeof hero); // outputs number
this.selectedHero = hero;
}
The onSelect method expects a parameter of type Hero
, but surprisingly, no errors are shown if a different type is passed in. Even assigning a number to this.selectedHero
does not cause an error.
Does this mean that template types
are not strictly enforced?
I would appreciate it if someone could point out what I am missing here.
Thank you