assertNever
Callable
- const print = (fruit: 'banana'|'kiwi') => {switch (fruit) {case 'banana': return '🍌 Banana';case 'kiwi': return '🥝 Kiwi';default: return assertNever(fruit); // <- This line will report an error if a case is missing}}
const print = (fruit: 'banana'|'kiwi') => {
switch (fruit) {
case 'banana': return '🍌 Banana';
case 'kiwi': return '🥝 Kiwi';
default: return assertNever(fruit); // <- This line will report an error if a case is missing
}
}
Raise a compile error when accessing this function and throws a TypeError at runtime This is useful for exhaustive switch check.