What does the `asserts` keyword do in a TypeScript type predicate?

TypeScript Professional Hard

TypeScript Professional — Hard

What does the `asserts` keyword do in a TypeScript type predicate?

Key points

  • `asserts` keyword narrows the type based on the assertion function
  • Only narrows the type if the function does not throw an error
  • Limited to the current scope of the code block

Ready to go further?

Related questions