tryError Documentation
Interface: ValidationError\<T\>
Interface
Defined in: [factories.ts:345](https://github.com/oconnorjohnson/try-error/blob/e3ae0308069a4fba073f4543d527ad76373db795/src/factories.ts#L345) Base type for validation errors with field-level details Provides a consistent structure for validation errors across different forms/inputs.
tryError API Documentation v0.0.1-alpha.1
tryError API Documentation / ValidationError
Interface: ValidationError<T>
Defined in: factories.ts:345
Base type for validation errors with field-level details
Provides a consistent structure for validation errors across different forms/inputs.
Example
interface FormValidationError extends ValidationError<"FormValidation"> {
readonly formId: string;
}
const error: FormValidationError = {
...createError({ type: "FormValidation", message: "Form validation failed" }),
fields: {
email: ["Must be a valid email address"],
password: ["Must be at least 8 characters", "Must contain a number"],
},
code: "FORM_VALIDATION_ERROR",
formId: "user-signup",
};
Extends
TryError
<T
>
Type Parameters
T
T
extends string
Properties
cause?
readonly optional cause: unknown;
Defined in: types.ts:50
The original error or thrown value that caused this error
Inherited from
code
readonly code: string;
Defined in: factories.ts:355
Validation error code for programmatic handling
context?
readonly optional context: Record<string, unknown>;
Defined in: types.ts:45
Additional context data for debugging
Inherited from
fields
readonly fields: Record<string, string[]>;
Defined in: factories.ts:350
Field-level validation errors Key is the field name, value is array of error messages for that field
message
readonly message: string;
Defined in: types.ts:25
Human-readable error message
Inherited from
source
readonly source: string;
Defined in: types.ts:35
Source location where the error occurred (file:line:column)
Inherited from
stack?
readonly optional stack: string;
Defined in: types.ts:30
Stack trace if available (may be stripped in production)
Inherited from
timestamp
readonly timestamp: number;
Defined in: types.ts:40
Timestamp when the error was created
Inherited from
type
readonly type: T;
Defined in: types.ts:20
The type of error - used for discriminated unions