generateRefinementsValidation()
generateRefinementsValidation<
T>(varName,refinements,ctx,options?):object
Experimental
Generates code to call multiple refinement functions in order.
Refinements are called sequentially in the order they were defined. If any refinement returns an error, validation stops and the error is returned.
Type Parametersโ
T: Tโ
Parametersโ
varName: stringโ
The variable name to validate
refinements: readonly RefinementFn<T>[]โ
Array of refinement functions to call
ctx: GeneratorContextโ
The generator context
options?: RefinementOptionsโ
Optional configuration for code generation
Returns: objectโ
Generated code lines and updated context
code: string[]โ
ctx: GeneratorContextโ
Sinceโ
2.0.0
Exampleโ
const refinements = [
(v: string) => v.length > 0 || "Cannot be empty",
(v: string) => /^[a-z]+$/.test(v) || "Must be lowercase"
];
const result = generateRefinementsValidation("value", refinements, ctx);
// Generated code calls each refinement in order