Using type assertions

In this lesson, we'll learn how to use type assertions to narrow the type of a variable.

Understanding the need for type assertions #

Sometimes we know more about a variable value than TypeScript does. Consider the code below; it would be nice to narrow the type of the value returned from getAge to number:

Get hands-on with 1200+ tech skills courses.