Skip to main content

generateUnionValidation()

generateUnionValidation(varName, ctx, constraints): object

Experimental

Generates complete validation code for a union schema. Automatically chooses the best strategy based on branch types.


Parametersโ€‹

varName: stringโ€‹

The variable name to validate

ctx: GeneratorContextโ€‹

The generator context

constraints: UnionConstraintMetaโ€‹

Union constraint metadata


Returns: objectโ€‹

Generated code lines and updated context

code: string[]โ€‹

ctx: GeneratorContextโ€‹


Sinceโ€‹

2.0.0


Exampleโ€‹

const result = generateUnionValidation("value", ctx, {
branches: [
{ typeName: "string", typeofCheck: "string", generateCode: stringGenerator },
{ typeName: "number", typeofCheck: "number", generateCode: numberGenerator }
]
});