Skip to content

Function.validateInstance

github-actions[bot] edited this page Jul 8, 2026 · 19 revisions

umt / validateInstance

Function: validateInstance()

validateInstance<T>(instance): Result<T, ValidationIssue[]>

Defined in: Decorator/validateInstance.ts:33

Validates every decorated field of an instance and aggregates the failures. Reads the rules registered by the field decorators along the prototype chain, so inherited rules are included.

Type Parameters

T

T extends object

The instance type.

Parameters

instance

T

The object to validate.

Returns

Result<T, ValidationIssue[]>

A success Result carrying the instance when every field is valid, otherwise an error Result carrying one issue per failing field.

Example

class User {
  @IsString name = "alice";
  @IsNumber age = 20;
}
const result = validateInstance(new User());
if (result.type === "error") {
  console.log(result.error);
}

API

Classes

Interfaces

Type Aliases

Variables

Functions

Clone this wiki locally