Netanel Basal

Starting from version 14, Angular adds the option of setting the page title through the router. We can set the title property in our route definition:

There are times when a dynamic title is needed. For example, we might want to show a todo’s title on a todo page…

You’ve probably used the as type assertion at least once when working with Typescript. For example:

Type assertions are a way to tell the compiler, “trust me, I know what I’m doing.”

The problem is that it doesn’t do any special data checking. TypeScript assumes that you, the programmer, have performed any special checks that you need.

Now let’s say we need to update our interface and add a new property:

We won’t get any Typescript errors in this case, which can lead to bugs in our application. A safer option is always to type the variable explicitly:

Follow me on Medium or Twitter to read more about Angular and JS!

Netanel Basal

Netanel Basal

A FrontEnd Tech Lead, blogger, and open source maintainer. The founder of ngneat, husband and father.