TypeScript · Senior · Question 61 of 75
What does an assertion function require to work as a narrowing call?
const assertUser: (x: unknown) => asserts x is User = (x) => { /* ... */ };- ✓Correct answer: The called function must have an explicit type annotation (an arrow without one can't be used as an assertion)
- 2It must be a class method
- 3It must return
true
Explanation
Otherwise TypeScript reports "Assertions require every name in the call target to be declared with an explicit type annotation".