Angular Shorties #6 — Casting Any
The angular engine infer types in templates, but sometimes want to make a casting in the template instead of using extra class variable…
Angular Shorties #6 — Casting Any

The angular engine infer types in templates, but sometimes we want to make a casting in the template instead of using extra class variable just for types mangling.
Consider the following snippet:
<input type="number" #i (change)="update(i.value)">
The update method signature:
class Comp {
update(value: number) {
}
}
The call for update from the template ends with build error, the i.value is a string even if the input type is a number and the update function expect for a number type.
In this example, the right solution is probably change the update method to accept string and then cast the value to number (see the first Angular shorties).
But in case we can not do that, the solution to eliminating the type check in the template is in the hands of the$any operator. A template casting function to “any”:
<input type="number" #i (change)="update($any(i.value))">
A message from our Founder
Hey, Sunil here. I wanted to take a moment to thank you for reading until the end and for being a part of this community.
Did you know that our team run these publications as a volunteer effort to over 3.5m monthly readers? We don’t receive any funding, we do this to support the community. ❤️
If you want to show some love, please take a moment to follow me on LinkedIn, TikTok, **Instagram. You can also subscribe to our [weekly newsletter](https://newsletter.plainenglish.io/)**.
And before you go, don’t forget to clap and follow the writer️!
메타데이터
- post_id
- fb58d62ebe73
- slug
- angular-shorties-6-casting-any-fb58d62ebe73
- url
- https://javascript.plainenglish.io/angular-shorties-6-casting-any-fb58d62ebe73
- canonical_url
- https://javascript.plainenglish.io/angular-shorties-6-casting-any-fb58d62ebe73
- author_url
- https://medium.com/@xpr
- status
- ok
- fetched_at
- 2026-07-17 17:40:40