Advanced TypeScript
Q87 / 100

What is the role of "asserts" in a function signature like "function assertIsString(val: unknown): asserts val is string"?

Correct! Well done.

Incorrect.

The correct answer is B) It is an assertion function: if it returns without throwing, TypeScript narrows val to string in subsequent code

B

Correct Answer

It is an assertion function: if it returns without throwing, TypeScript narrows val to string in subsequent code

Explanation

Assertion functions use "asserts" to tell the type checker that if the function returns normally (doesn't throw), the asserted condition holds for the rest of the scope.

Progress
87/100