import { param } from "https://deno.land/x/ayonli_jsext@v0.9.72/class/decorators.ts";
A decorator that restrains the input arguments of the method at runtime, based on Zod.
NOTE: Although this decorator accepts a parameter name, it is not bound to the actually parameter in the method definition, it is only used for the error message. The parameter is bound by the appearance order of the decorator.
Examples
Example 1
Example 1
import { param } from "@ayonli/jsext/class/decorators";
import { z } from "zod";
class Calculator {
\ ("a", z.number())
\ ("b", z.number())
add(a: number, b: number) {
return a + b;
}
}
const calc = new Calculator();
// \@ts-ignore for demonstration
console.log(calc.add("2", 3));
// throws:
// TypeError: validation failed at parameter a: expected number, received string
Parameters
type: T