Recall & Review
beginner
What is the
never type in TypeScript?The
never type represents values that never occur. It is used for functions that never return or variables that cannot have any value.Click to reveal answer
beginner
When does TypeScript consider code to be unreachable?
Code is unreachable if it can never be executed, for example, code after a function that always throws an error or an infinite loop.
Click to reveal answer
beginner
What happens if a function has a return type of
never?It means the function never finishes normally. It either throws an error or runs forever, so it never returns a value.
Click to reveal answer
intermediate
Why is the
never type useful for exhaustive checks?It helps catch missing cases in code like
switch statements by making sure all possibilities are handled, otherwise TypeScript shows an error.Click to reveal answer
beginner
Give an example of unreachable code in TypeScript.
Example: <pre>function example() { return; console.log('unreachable'); }</pre> The <code>console.log</code> line is unreachable because the function returns before it.Click to reveal answer
What does the
never type represent in TypeScript?✗ Incorrect
The
never type means a value that never happens, like a function that never returns.Which of these is an example of unreachable code?
✗ Incorrect
Code after a return statement is unreachable because the function stops running at return.
What will a function with return type
never do?✗ Incorrect
A
never function never returns normally; it throws or loops forever.How does TypeScript help with unreachable code?
✗ Incorrect
TypeScript warns you when code can never be reached, helping you find mistakes.
Why use
never in exhaustive checks?✗ Incorrect
Using
never forces you to handle all cases, so TypeScript catches missing ones.Explain what the
never type means and give an example of a function that returns never.Think about functions that never finish normally.
You got /3 concepts.
Describe what unreachable code is and why TypeScript warns about it.
Consider what happens after a return statement.
You got /3 concepts.