TypeScript Basics Part II

We'll introduce ourselves to a few more TypeScript concepts in this lesson.

We'll cover the following

Type assertions

Sometimes you may end up in a situation where you know more about the type of a variable than TypeScript. This is typically the case when you know the type of a variable to be more specific than its current type.

This is where type assertions come in. It’s essentially a way for you to tell the TypeScript compiler that you know what you’re doing.

A type assertion is like a type cast in other languages, but it does not perform special checking or data restructuring. It does not have any runtime impact and is used strictly by the compiler. There are two ways of performing type assertions.

Get hands-on with 1200+ tech skills courses.