Assertion Functions

This lesson gives more details about assertion functions.

The assertion function is new to TypeScript version 3.7. It aims to not only ensure that a value is of a specific type but also to throw at (runtime) an exception if it does not respect the expected type. The assertion function use cases are more oriented for a codebase that is coming from Javascript where asserting types was a common practice. With a TypeScript-only codebase, it is not as needed since type is defined at the declaration.

Get hands-on with 1200+ tech skills courses.