Narrow the unknown Type with TypeScript's Assertion Functions

Marius Schulz
InstructorMarius Schulz

Share this video with your friends

Send Tweet

This lesson introduces assertion functions which let us narrow the type of a variable or property for the remainder of the containing scope. We're going to learn how to create an assertion function by using the asserts keyword in the function signature. In particular, we're going to focus on narrowing the unknown type to a more specific type.

Additional Reading

Skylar Bolton
Skylar Bolton
~ 2 months ago

Well done! I can see multiple uses for this kind of reasoning and "defense" when writing open-source packages.