@luolapeikko/ts-common
    Preparing search index...

    Function errorAs

    • Wraps an error in a custom error type.

      Type Parameters

      • ET extends Error

        The custom error type that extends Error.

      Parameters

      • err: unknown

        The error to wrap.

      • ErrorClass: new (message?: string) => ET

        The constructor of the error class to use.

      Returns ET

      An instance of the custom error type with the original message and stack trace.

      try {
      // ...
      } catch (err) {
      throw errorAs(err, TypeError); // throws TypeError
      }

      v0.3.0