Types
TypeScript type definitions for valrs
Type Definitions
Complete TypeScript type definitions exported by valrs.
Type Inference Utilities
v.infer<T>
Infers the output type from a schema. This is the primary type inference utility, matching Zod's z.infer.
Usage:
v.input<T>
Infers the input type from a schema. Use this when the input type differs from the output type (e.g., with coercion or transforms).
Usage:
v.output<T>
Infers the output type from a schema. This is an alias for v.infer that provides symmetry with v.input.
Usage:
SafeParse Result Types
SafeParseResult<T>
The result of a safeParse() call. A discriminated union that is either a success or failure.
Usage:
SafeParseSuccess<T>
The result of a successful safeParse() call.
| Property | Type | Description |
|---|---|---|
success | true | Discriminator indicating success |
data | T | The validated and parsed value |
error | undefined | Always undefined on success |
SafeParseError
The result of a failed safeParse() call.
| Property | Type | Description |
|---|---|---|
success | false | Discriminator indicating failure |
error | ValError | The error containing validation issues |
data | undefined | Always undefined on failure |
Type Guards
Error Types
ValError
Error class thrown when schema.parse() fails. Contains detailed information about all validation issues with Zod-compatible error codes and formatting methods.
Usage:
ValIssue
Union of all issue types. Each issue has a code discriminator that determines its shape.
ValIssueCode
All possible Zod-compatible validation error codes.
ValIssueBase
Base interface for all validation issues.
| Property | Type | Description |
|---|---|---|
code | ValIssueCode | The error code identifying the issue type |
path | (string | number)[] | Path to the invalid value |
message | string | Human-readable error message |
Specific Issue Types
InvalidTypeIssue
Issue for type validation failures.
Example:
TooSmallIssue
Issue for values that are too small (strings, numbers, arrays, sets, dates, bigints).
Example:
TooBigIssue
Issue for values that are too big.
Example:
InvalidStringIssue
Issue for invalid string format.
Example:
InvalidEnumValueIssue
Issue for enum validation failures.
Example:
InvalidUnionIssue
Issue for union validation failures.
InvalidUnionDiscriminatorIssue
Issue for discriminated union validation failures.
UnrecognizedKeysIssue
Issue for unrecognized object keys (when using .strict()).
Example:
InvalidLiteralIssue
Issue for literal value validation failures.
CustomIssue
Issue for custom validation failures (from .refine() or .superRefine()).
NotMultipleOfIssue
Issue for values that are not a multiple of a given number.
NotFiniteIssue
Issue for non-finite number values.
InvalidDateIssue
Issue for invalid Date values.
InvalidArgumentsIssue
Issue for invalid function arguments.
InvalidReturnTypeIssue
Issue for invalid function return type.
InvalidIntersectionTypesIssue
Issue for intersection type validation failures.
Error Formatting Types
FormattedError<T>
Type for the nested error format returned by ValError.format().
Usage:
FlattenedError<T>
Type for the flattened error format returned by ValError.flatten().
Usage:
Error Map Types
ErrorMapFn
Function type for custom error messages.
ErrorMapContext
Context provided to error map functions.
Usage:
Standard Schema Types
StandardSchemaV1
The core Standard Schema interface that all valrs schemas implement.
StandardJSONSchemaV1
Extended interface for schemas that support JSON Schema generation.
ValidationResult
The result of a validation operation. A discriminated union based on the presence of issues.
Success case: Contains value of type T, issues is undefined
Failure case: Contains issues array, value is undefined
ValidationIssue
Describes why validation failed (Standard Schema format).
| Property | Type | Description |
|---|---|---|
message | string | Human-readable error message |
path | PathSegment[] | Path to the invalid value (optional) |
PathSegment
A segment in a validation issue path.
Examples:
'name'- String property key0- Array index{ key: 'special.key' }- Object with explicit key property
JsonSchemaOptions
Options passed to JSON Schema generation functions.
| Property | Type | Description |
|---|---|---|
target | string | Target format: 'draft-2020-12', 'draft-07', or 'openapi-3.0' |
InferInput
Infer the input type from a Standard Schema.
Usage:
InferOutput
Infer the output type from a Standard Schema.
Usage:
Exports
All types are exported from the main package: