method ValidationService.prototype.validate
ValidationService.prototype.validate<T>(
schema: unknown,
data: unknown
): Result<T, readonly ValidationIssue[]>

Validate data against the given schema.

The schema is expected to expose a safeParse method (Zod-compatible). On success the parsed value is returned wrapped in ok(); on failure the validator issues are mapped to ValidationIssue elements and returned via err().

Type Parameters

The validated output type

Parameters

schema: unknown

The schema object (must have safeParse)

data: unknown

The value to validate

Return Type

Result<T, readonly ValidationIssue[]>

Ok with the parsed value or Err with the issues

Throws

TypeError

When the schema does not expose a safeParse method

Usage

import { ValidationService } from "validation-plugin/src/index.ts";