API reference

Everything ships from the single entry point, typebox-standard-schema.

ExportDescription
TypeThe schema builder — all TypeBox factories (Object, String, Union, Cyclic, …), every result carrying ~standard, plus the methods below.
Type.Readonly(schema)Marks a field as output-only (readOnly: true) — kept by Type.Read, cut by Type.Write. Replaces TypeBox’s own type-level-only Readonly.
Type.Writeonly(schema)Marks a field as input-only (writeOnly: true) — kept by Type.Write, cut by Type.Read.
Type.Read(schema, options?)Output projection: drops writeOnly fields (runtime + static). Memoized per schema; with options returns a standalone named clone.
Type.Write(schema, options?)Input projection: drops readOnly fields. Same memoization and options.
Type.Partial(schema, options?)TypeBox’s Partial + strips property defaults for PATCH-safe partial updates.
validate(schema, data)Runs the pipeline above; returns { success: true, data } or { success: false, errors }. data is typed as the shape actually checked — see TValidated.
parse(schema, data)Assert-style: returns the validated data or throws a ValidationError.
isValidationError(e)Type guard for the error parse throws (e.issues carries the details).
adopt(schema)Attaches ~standard to a schema built outside this package.
FormatThe format registry — Format.Set('name', fn) to register custom string formats; a change recompiles schemas on their next validation.
ValueRe-export of typebox/value for ad-hoc operations (Value.Check, Value.Clone, …).
Static<T>Static type inference for a schema (re-exported from typebox).
ValidationResult<T>, ValidationIssue, ValidationErrorThe result union, the issue shape, and the error parse throws.
TRead<T>, TWrite<T>, TReadonly<T>, TWriteonly<T>Type-level companions of the projections and field marks.
TValidated<T>The shape validate checks: TWrite<T> for a full schema, T itself when it already is a projection.
ProjectionOptionsOptions accepted by Type.Read/Type.Write (suffix + any schema options).
schema['~standard'].jsonSchemainput(options) / output(options) — Standard JSON Schema: a fresh JSON Schema of what the schema validates.
JsonSchemaTarget, JsonSchemaOptions'draft-2020-12' \| 'draft-07' \| 'openapi-3.0', and { target, libraryOptions? } (keepIds, inlineRoot, components).
StandardProps, WithStandard<T>The ~standard interface shape and the type adopt returns.
TSchema, TObject, TArray, TOptional, TProperties, TSchemaOptionsCommon TypeBox types, re-exported for convenience.

Last updated · Edit this page on GitHub