Skip to content

@pcvl/schema / Result

Type Alias: Result<Output> ​

ts
type Result<Output> = 
  | StandardSchemaV1.SuccessResult<Output>
  | FailureResult;

Defined in: result.ts:45

What every .validate() call returns. It is a union of two branches, told apart by whether issues is present: on success the accepted (and, after a .transform(), transformed) value is on value; on failure issues lists what was wrong. .validate() never throws for an invalid value.

Type Parameters ​

Output ​

Output

Example ​

ts
import { pvl, type Result } from '@pcvl/schema';

const result: Result<string> = pvl.string().validate('hello');
if (result.issues) {
  console.log(result.issues.map((issue) => issue.message));
} else {
  console.log(result.value); // 'hello'
}