import { throws } from "https://deno.land/x/ayonli_jsext@v0.9.72/class/decorators.ts";
A decorator that restrains the thrown value of the method at runtime, based on Zod.
Examples
Example 1
Example 1
import { throws } from "@ayonli/jsext/class/decorators";
import { z } from "zod";
class Calculator {
\ (z.instanceof(RangeError))
div(a: number, b: number) {
if (b === 0) {
throw new TypeError("division by zero");
}
return a / b;
}
}
const calc = new Calculator();
console.log(calc.div(2, 0));
// throws:
// TypeError: validation failed at thrown value: not an instance of RangeError
Parameters
type: T