Skip to content

Glossary: TypeScript Beyond the Basics

Assertion function

Also written: assertion functions, asserts

A function declared with `asserts` that throws if a check fails. After it returns, TypeScript treats the check as true, so `assert(stock !== null, ...)` makes `stock` a number afterwards.

Where the book teaches it

Related terms

assertNeverType predicate