Like a quality inspector — if they sign off, you know the item passed inspection.
asserts condition tells TypeScript that if the function returns normally (no throw), condition is truthy. Any code after assert(x) knows x is truthy.
> assert(user !== null)
> TypeScript: user is not null after this line
> assert(false) → throws Error("Assertion failed")Like a quality inspector — if they sign off, you know the item passed inspection.
asserts condition tells TypeScript that if the function returns normally (no throw), condition is truthy. Any code after assert(x) knows x is truthy.
> assert(user !== null)
> TypeScript: user is not null after this line
> assert(false) → throws Error("Assertion failed")Sign in to cast your vote
Sign in to share your feedback and join the discussion.