Q06. What is never used for?
never represents a value that cannot occur. It appears as the return type of functions that never complete normally and as the remainder of an exhaustively narrowed union. Assigning a supposedly impossible value to never can detect missing union cases.
When every Shape variant is handled, the default branch should be never. Adding a variant without a case then becomes a compile-time error.
Note
Interview approach: define the concept, explain why it matters, then mention one trade-off or limitation.
Exhaustive check
function unreachable(value: never): never {
throw new Error(String(value));
}💡 The never parameter is a useful compile-time signal for impossible cases.
Key Takeaways
- Explain the concept in your own words.
- Know the practical trade-off and its limits.
- Use a small example to demonstrate the idea.
Knowledge Check
What should the remaining value of a fully exhausted discriminated union be?