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) => { /* ... */ };

Explanation

Otherwise TypeScript reports "Assertions require every name in the call target to be declared with an explicit type annotation".

Further reading

Problem with a question

TypeScript · Senior · question 61

Test yourself

Take the TypeScript · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz