---
url: /unthrown/api/standard-schema.md
---
**@unthrown/standard-schema**

***

# @unthrown/standard-schema

## Type Aliases

### SchemaIssues

```ts
type SchemaIssues = readonly StandardSchemaV1.Issue[];
```

Defined in: [index.ts:21](https://github.com/btravstack/unthrown/blob/714d47b5e9046721c5024e1da43601cb9a2843d9/packages/standard-schema/src/index.ts#L21)

The error channel both entry points produce: a schema's validation issues.

## Functions

### fromSchema()

```ts
function fromSchema<S>(schema): (input) => Result<InferOutput<S>, SchemaIssues>;
```

Defined in: [index.ts:63](https://github.com/btravstack/unthrown/blob/714d47b5e9046721c5024e1da43601cb9a2843d9/packages/standard-schema/src/index.ts#L63)

Turn a **synchronous** Standard Schema into a validator returning a
`Result`.

#### Type Parameters

| Type Parameter | Description |
| ------ | ------ |
| `S` *extends* `StandardSchemaV1`<`unknown`, `unknown`> | the schema type. |

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `schema` | `S` | a Standard Schema validator. |

#### Returns

a function mapping an input to `Result<Output, SchemaIssues>`.

(`input`) => `Result`<`InferOutput`<`S`>, [`SchemaIssues`](#schemaissues)>

#### Remarks

Validation issues are the modeled error `E` — `Result<Output, SchemaIssues>` —
because a failed validation is an *anticipated* outcome, not a Defect. Works
with any Standard Schema implementation (Zod, Valibot, ArkType, …).

A validator that **throws** (rather than returning issues) becomes a `Defect`
— the same boundary behaviour as `fromThrowable`, so an unexpected crash never
escapes as a raw exception. If the schema validates **asynchronously**
(its `validate` returns a `Promise`), a synchronous `Result` cannot represent
the pending work, so this throws a `TypeError` — a deliberate usage error; use
[fromSchemaAsync](#fromschemaasync) instead.

#### Example

```ts
import { fromSchema } from "@unthrown/standard-schema";
const parse = fromSchema(z.string());
parse("hi").get(); // "hi"
parse(42).getErr(); // the issues array
```

***

### fromSchemaAsync()

```ts
function fromSchemaAsync<S>(schema): (input) => AsyncResult<InferOutput<S>, SchemaIssues>;
```

Defined in: [index.ts:122](https://github.com/btravstack/unthrown/blob/714d47b5e9046721c5024e1da43601cb9a2843d9/packages/standard-schema/src/index.ts#L122)

Turn a Standard Schema (sync **or** async) into a validator returning an
`AsyncResult`.

#### Type Parameters

| Type Parameter | Description |
| ------ | ------ |
| `S` *extends* `StandardSchemaV1`<`unknown`, `unknown`> | the schema type. |

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `schema` | `S` | a Standard Schema validator. |

#### Returns

a function mapping an input to `AsyncResult<Output, SchemaIssues>`.

(`input`) => `AsyncResult`<`InferOutput`<`S`>, [`SchemaIssues`](#schemaissues)>

#### Remarks

The async counterpart of [fromSchema](#fromschema): it awaits the schema's
`validate`, so it accepts both synchronous and asynchronous schemas. As with
every `AsyncResult`, the returned value never rejects — a validator that
*throws* (rather than returning issues) becomes a `Defect`.

#### Example

```ts
import { fromSchemaAsync } from "@unthrown/standard-schema";
const parse = fromSchemaAsync(asyncSchema);
(await parse(input)).match({ ok, errCases, defect });
```
