• Make an assertion that error is an Error. If not then an error will be thrown. An error class and a string that should be included in the error message can also be asserted.

    Type Parameters

    • E extends Error = Error

    Parameters

    • error: unknown
    • Optional ErrorClass: (new (...args) => E)
        • new (...args): E
        • Parameters

          • Rest ...args: any[]

          Returns E

    • Optional msgMatches: string | RegExp
    • Optional msg: string

    Returns asserts error is E

    Since

    24.7.0

    Example

    import { assertIsError } from "assert";

    assertIsError(null); // Throws
    assertIsError(new RangeError("Out of range")); // Doesn't throw
    assertIsError(new RangeError("Out of range"), SyntaxError); // Throws
    assertIsError(new RangeError("Out of range"), SyntaxError, "Out of range"); // Doesn't throw
    assertIsError(new RangeError("Out of range"), SyntaxError, "Within range"); // Throws