Skip to main content

assertNever

Callable

  • assertNever<V>(subject: V): V

  • Raise a compile error when accessing this function and throws a TypeError at runtime This is useful for exhaustive switch check.

    @example
    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
    }
    }

    Type parameters

    • V: never