[API reference](https://evolu.dev/docs/api-reference) › [@evolu/common](https://evolu.dev/docs/api-reference/common) › [Type](https://evolu.dev/docs/api-reference/common/Type) › Type

Defined in: [packages/common/src/Type.ts:502](https://github.com/evoluhq/evolu/blob/f9257a718488bcc2c10afa2edb761c0eee5f5410/packages/common/src/Type.ts#L502)

A runtime representation of a TypeScript type, including its encoded input,
semantic output, structured errors, and canonical encoding.

See the [Type overview](https://evolu.dev/docs/api-reference/common/Type).

## Extends

- [`TypeNode`](https://evolu.dev/docs/api-reference/common/Type/interfaces/TypeNode)

## Extended by

- [`TransformType`](https://evolu.dev/docs/api-reference/common/Type/interfaces/TransformType)
- [`ObjectTagType`](https://evolu.dev/docs/api-reference/common/Type/interfaces/ObjectTagType)
- [`InstanceOfType`](https://evolu.dev/docs/api-reference/common/Type/interfaces/InstanceOfType)
- [`LiteralType`](https://evolu.dev/docs/api-reference/common/Type/interfaces/LiteralType)
- [`UnionType`](https://evolu.dev/docs/api-reference/common/Type/interfaces/UnionType)
- [`TemplateLiteralParserType`](https://evolu.dev/docs/api-reference/common/Type/interfaces/TemplateLiteralParserType)
- [`TemplateLiteralType`](https://evolu.dev/docs/api-reference/common/Type/interfaces/TemplateLiteralType)
- [`BrandType`](https://evolu.dev/docs/api-reference/common/Type/interfaces/BrandType)
- [`TableId`](https://evolu.dev/docs/api-reference/common/Type/interfaces/TableId)
- [`ArrayType`](https://evolu.dev/docs/api-reference/common/Type/interfaces/ArrayType)
- [`SetType`](https://evolu.dev/docs/api-reference/common/Type/interfaces/SetType)
- [`MapType`](https://evolu.dev/docs/api-reference/common/Type/interfaces/MapType)
- [`TupleType`](https://evolu.dev/docs/api-reference/common/Type/interfaces/TupleType)
- [`RecordType`](https://evolu.dev/docs/api-reference/common/Type/interfaces/RecordType)
- [`DiscriminatedUnionType`](https://evolu.dev/docs/api-reference/common/Type/interfaces/DiscriminatedUnionType)
- [`LazyType`](https://evolu.dev/docs/api-reference/common/Type/interfaces/LazyType)
- [`DataType`](https://evolu.dev/docs/api-reference/common/Type/interfaces/DataType)
- [`JsonValueType`](https://evolu.dev/docs/api-reference/common/Type/interfaces/JsonValueType)
- [`JsonObjectType`](https://evolu.dev/docs/api-reference/common/Type/interfaces/JsonObjectType)

## Properties

<a id="concretetypesymbol"></a>

### \[concreteTypeSymbol\]

```ts
readonly [concreteTypeSymbol]: true;
```

Defined in: [packages/common/src/Type.ts:580](https://github.com/evoluhq/evolu/blob/f9257a718488bcc2c10afa2edb761c0eee5f5410/packages/common/src/Type.ts#L580)

---

<a id="customfromsymbol"></a>

### \[customFromSymbol\]

```ts
readonly [customFromSymbol]: CustomFrom;
```

Defined in: [packages/common/src/Type.ts:584](https://github.com/evoluhq/evolu/blob/f9257a718488bcc2c10afa2edb761c0eee5f5410/packages/common/src/Type.ts#L584)

#### Overrides

[`TypeNode`](https://evolu.dev/docs/api-reference/common/Type/interfaces/TypeNode).[`[customFromSymbol]`](/docs/api-reference/common/Type/interfaces/TypeNode#customfromsymbol)

---

<a id="errorssymbol"></a>

### \[errorsSymbol\]

```ts
readonly [errorsSymbol]: Errors;
```

Defined in: [packages/common/src/Type.ts:576](https://github.com/evoluhq/evolu/blob/f9257a718488bcc2c10afa2edb761c0eee5f5410/packages/common/src/Type.ts#L576)

#### Overrides

[`TypeNode`](https://evolu.dev/docs/api-reference/common/Type/interfaces/TypeNode).[`[errorsSymbol]`](/docs/api-reference/common/Type/interfaces/TypeNode#errorssymbol)

---

<a id="identityencodingsymbol"></a>

### \[identityEncodingSymbol\]

```ts
readonly [identityEncodingSymbol]: IdentityEncoding;
```

Defined in: [packages/common/src/Type.ts:587](https://github.com/evoluhq/evolu/blob/f9257a718488bcc2c10afa2edb761c0eee5f5410/packages/common/src/Type.ts#L587)

#### Overrides

[`TypeNode`](https://evolu.dev/docs/api-reference/common/Type/interfaces/TypeNode).[`[identityEncodingSymbol]`](/docs/api-reference/common/Type/interfaces/TypeNode#identityencodingsymbol)

---

<a id="standard"></a>

### ~standard

```ts
readonly ~standard: Props<Input, Output>;
```

Defined in: [packages/common/src/Type.ts:527](https://github.com/evoluhq/evolu/blob/f9257a718488bcc2c10afa2edb761c0eee5f5410/packages/common/src/Type.ts#L527)

Standard Schema V1 interoperability.

Validation runs the complete `fromUnknown` pipeline synchronously and
reports every structured failure as a localized message with a separate
property path.

#### Overrides

[`TypeNode`](https://evolu.dev/docs/api-reference/common/Type/interfaces/TypeNode).[`~standard`](https://evolu.dev/docs/api-reference/common/Type/interfaces/TypeNode#standard)

---

<a id="canonicalinput-1"></a>

### CanonicalInput

```ts
CanonicalInput: CanonicalInput;
```

Defined in: [packages/common/src/Type.ts:512](https://github.com/evoluhq/evolu/blob/f9257a718488bcc2c10afa2edb761c0eee5f5410/packages/common/src/Type.ts#L512)

The statically known subtype of [Input](https://evolu.dev/docs/api-reference/common/Type/interfaces/Type#input) returned by the complete `to`
operation.

Compared with Input, CanonicalInput can exclude invalid candidates and
alternative representations that encoding cannot emit. It can remain wider
than the values actually emitted when a refinement follows an arbitrary
transformation. Structural Types derive it from the CanonicalInput of their
contained Types.

This is a type-only phantom property. Use it through `typeof
Type.CanonicalInput`; it does not exist at runtime.

#### Overrides

[`TypeNode`](https://evolu.dev/docs/api-reference/common/Type/interfaces/TypeNode).[`CanonicalInput`](https://evolu.dev/docs/api-reference/common/Type/interfaces/TypeNode#canonicalinput)

---

<a id="error-1"></a>

### Error

```ts
Error: Error;
```

Defined in: [packages/common/src/Type.ts:506](https://github.com/evoluhq/evolu/blob/f9257a718488bcc2c10afa2edb761c0eee5f5410/packages/common/src/Type.ts#L506)

The error introduced at this Type node.

This is a type-only phantom property. Use it through `typeof Type.Error`;
it does not exist at runtime.

#### Overrides

[`TypeNode`](https://evolu.dev/docs/api-reference/common/Type/interfaces/TypeNode).[`Error`](https://evolu.dev/docs/api-reference/common/Type/interfaces/TypeNode#error)

---

<a id="formaterror"></a>

### formatError

```ts
readonly formatError: TypeErrorFormatter<Errors>;
```

Defined in: [packages/common/src/Type.ts:646](https://github.com/evoluhq/evolu/blob/f9257a718488bcc2c10afa2edb761c0eee5f5410/packages/common/src/Type.ts#L646)

Formats an error returned by `fromUnknown` or `from` as one human-readable
message. Predefined Types use English; [localizeTypes](https://evolu.dev/docs/api-reference/common/Type/variables/localizeTypes) derives Types
with localized formatters.

Structural errors retain nested errors and their locations in the typed
error value. This formatter does not encode paths or enumerate nested
errors in its message.

### Example

```ts
import {
  assertEqual,
  assertType,
  Data,
  assertErr,
  String,
} from "@evolu/common";

const result = String.fromUnknown(42);

assertErr(result);
assertType(Data, result.error);
assertEqual(result.error, {
  type: "TypeOf",
  expected: "String",
  value: 42,
});
assertEqual(String.formatError(result.error), "A value 42 is not a string.");
```

---

<a id="from"></a>

### from

```ts
readonly from: [CustomFrom] extends [never] ? [Parent] extends [P] ? FromOperation<Output, Error, P> : (value: Output, options?: ValidationOptions) => Result<Output, never> : CustomFrom;
```

Defined in: [packages/common/src/Type.ts:738](https://github.com/evoluhq/evolu/blob/f9257a718488bcc2c10afa2edb761c0eee5f5410/packages/common/src/Type.ts#L738)

Runs the remaining Type pipeline from a typed boundary.

`from` accepts this Type's `Output`. Its first `.parent` accepts the
immediate parent Output, and each additional suffix moves the boundary one
Type toward the root. The deepest suffix accepts the root Output.

Every entry point asserts its selected boundary before running the
remaining pipeline. Assertion failures throw because they indicate a
developer error. The Error message identifies the expected boundary Type,
and its cause preserves the structured validation error. Only failures
introduced after that boundary are returned through `Result`.

### Example

A form already guarantees every constraint on a title, while a new note
input guarantees only trimmed text. The note's parent boundary validates
only the constraints that the form does not guarantee:

```ts
import {
  assertOk,
  assertType,
  flatMapResult,
  NonEmptyTrimmedString100,
  object,
  TrimmedString,
  type MaxLengthError,
  type MinLengthError,
  type Result,
} from "@evolu/common";

const Todo = object({
  title: NonEmptyTrimmedString100,
  note: NonEmptyTrimmedString100,
});

const saveTodo = (title: NonEmptyTrimmedString100, note: TrimmedString) => {
  // @ts-expect-error TrimmedString does not guarantee a non-empty value
  // with at most 100 characters.
  Todo.from({ title, note });

  return flatMapResult(Todo.props.note.from.parent.parent(note), (note) =>
    Todo.from({ title, note }),
  );
};

const title = NonEmptyTrimmedString100.orThrow("Buy milk");
const note = TrimmedString.orThrow("Remember oat milk");
const result = saveTodo(title, note);

assertType<
  Result<typeof Todo.Output, MaxLengthError<100> | MinLengthError<1>>,
  typeof result
>();
assertOk(result, { title, note });
```

---

<a id="fromunknown"></a>

### fromUnknown

```ts
readonly fromUnknown: (value: unknown, options?: ValidationOptions) => Result<Output, Errors>;
```

Defined in: [packages/common/src/Type.ts:606](https://github.com/evoluhq/evolu/blob/f9257a718488bcc2c10afa2edb761c0eee5f5410/packages/common/src/Type.ts#L606)

Decodes an unknown value through the complete Type pipeline.

### Example

```ts

const value: unknown = 42;
const result = PositiveInt.fromUnknown(value);

assertOk(result, 42);
```

#### Overrides

[`TypeNode`](https://evolu.dev/docs/api-reference/common/Type/interfaces/TypeNode).[`fromUnknown`](https://evolu.dev/docs/api-reference/common/Type/interfaces/TypeNode#fromunknown)

---

<a id="input-1"></a>

### Input

```ts
Input: Input;
```

Defined in: [packages/common/src/Type.ts:504](https://github.com/evoluhq/evolu/blob/f9257a718488bcc2c10afa2edb761c0eee5f5410/packages/common/src/Type.ts#L504)

The complete typed decoding boundary accepted by `orThrow`, `orNull`, and
the deepest available `from` operation.

Input includes candidates that validation can reject and noncanonical
representations that decoding can normalize.

This is a type-only phantom property. Use it through `typeof Type.Input`;
it does not exist at runtime.

#### Overrides

[`TypeNode`](https://evolu.dev/docs/api-reference/common/Type/interfaces/TypeNode).[`Input`](https://evolu.dev/docs/api-reference/common/Type/interfaces/TypeNode#input)

---

<a id="is"></a>

### is

```ts
readonly is: (value: unknown) => value is Output;
```

Defined in: [packages/common/src/Type.ts:674](https://github.com/evoluhq/evolu/blob/f9257a718488bcc2c10afa2edb761c0eee5f5410/packages/common/src/Type.ts#L674)

Checks whether an unknown value is a valid semantic `Output`.

This is an exact Output-membership check, not a test of whether an encoded
Input could be decoded. It can be used directly as a TypeScript type guard,
including as an Array filter predicate.

### Example

```ts
import {
  assertFalse,
  assertType,
  assertTrue,
  Int64FromInt64String,
  type Int64,
} from "@evolu/common";

const values: ReadonlyArray<unknown> = [42n, "42", null];
const integers = values.filter(Int64FromInt64String.is);

assertType<Array<Int64>, typeof integers>();
assertTrue(Int64FromInt64String.is(42n));
assertFalse(Int64FromInt64String.is("42"));
```

#### Overrides

[`TypeNode`](https://evolu.dev/docs/api-reference/common/Type/interfaces/TypeNode).[`is`](https://evolu.dev/docs/api-reference/common/Type/interfaces/TypeNode#is)

---

<a id="name-1"></a>

### name

```ts
readonly name: Name;
```

Defined in: [packages/common/src/Type.ts:518](https://github.com/evoluhq/evolu/blob/f9257a718488bcc2c10afa2edb761c0eee5f5410/packages/common/src/Type.ts#L518)

The name identifying this Type node.

#### Overrides

[`TypeNode`](https://evolu.dev/docs/api-reference/common/Type/interfaces/TypeNode).[`name`](https://evolu.dev/docs/api-reference/common/Type/interfaces/TypeNode#name)

---

<a id="ornull"></a>

### orNull

```ts
readonly orNull: (value: Input) => Output | null;
```

Defined in: [packages/common/src/Type.ts:847](https://github.com/evoluhq/evolu/blob/f9257a718488bcc2c10afa2edb761c0eee5f5410/packages/common/src/Type.ts#L847)

Shorthand for calling [getOrNull](https://evolu.dev/docs/api-reference/common/Result/functions/getOrNull) with the result of the deepest
`from` operation, which accepts this Type's `Input`.

The typed `Input` boundary is asserted before the remaining pipeline runs.
A boundary violation throws a developer error directly; `getOrNull` maps
only a validation error returned after that boundary to `null`.

`Type.orNull.parent(value)` does not exist. To return `null` after starting
from a typed boundary, call `getOrNull` with the corresponding `from`
operation.

Use `orNull` when absence is the complete meaning of failure and the error
is intentionally irrelevant. Use `fromUnknown` or a typed `from` operation
when the caller needs to inspect, format, or otherwise handle the error.

### Example

```ts

const NonEmptyString = minLength(1)(String);

const value = NonEmptyString.orNull("Evolu");

// Equivalent because `from.parent` is this Type's deepest `from` operation:
const sameValue = getOrNull(NonEmptyString.from.parent("Evolu"));

assertEqual(value, "Evolu");
assertEqual(sameValue, value);
assertEqual(NonEmptyString.orNull(""), null);
```

### orThrow

```ts
readonly orThrow: (value: Input, options?: ValidationOptions) => Output;
```

Defined in: [packages/common/src/Type.ts:807](https://github.com/evoluhq/evolu/blob/f9257a718488bcc2c10afa2edb761c0eee5f5410/packages/common/src/Type.ts#L807)

Shorthand for calling [getOrThrow](https://evolu.dev/docs/api-reference/common/Result/functions/getOrThrow) with the result of the deepest
`from` operation, which accepts this Type's `Input`.

The typed `Input` boundary is asserted before the remaining pipeline runs.
A boundary violation throws a developer error directly; `getOrThrow` maps
only a validation error returned after that boundary.

`Type.orThrow.parent(value)` does not exist. To throw after starting from a
typed boundary, call `getOrThrow` with the corresponding `from` operation.

Use `orThrow` for startup and configuration, module constants, test
fixtures, and internal invariants where failure must stop the current flow.
Prefer `fromUnknown` or a typed `from` operation for ordinary application
input whose validation failure can be reported or recovered from.

### Example

```ts

const NonEmptyString = minLength(1)(String);

const value = NonEmptyString.orThrow("Evolu");

// Equivalent because `from.parent` is this Type's deepest `from` operation:
const sameValue = getOrThrow(NonEmptyString.from.parent("Evolu"));

assertEqual(value, "Evolu");
assertEqual(sameValue, value);
```

### Output

```ts
Output: Output;
```

Defined in: [packages/common/src/Type.ts:505](https://github.com/evoluhq/evolu/blob/f9257a718488bcc2c10afa2edb761c0eee5f5410/packages/common/src/Type.ts#L505)

The semantic value produced by decoding and accepted by bare `from` and
`to`.

This is a type-only phantom property. Use it through `typeof Type.Output`;
it does not exist at runtime.

#### Overrides

[`TypeNode`](https://evolu.dev/docs/api-reference/common/Type/interfaces/TypeNode).[`Output`](https://evolu.dev/docs/api-reference/common/Type/interfaces/TypeNode#output)

---

<a id="parent-1"></a>

### parent

```ts
readonly parent: Parent;
```

Defined in: [packages/common/src/Type.ts:590](https://github.com/evoluhq/evolu/blob/f9257a718488bcc2c10afa2edb761c0eee5f5410/packages/common/src/Type.ts#L590)

The one preceding Type node, or `null` for a root Type.

#### Overrides

[`TypeNode`](https://evolu.dev/docs/api-reference/common/Type/interfaces/TypeNode).[`parent`](https://evolu.dev/docs/api-reference/common/Type/interfaces/TypeNode#parent)

---

<a id="to"></a>

### to

```ts
readonly to: [Parent] extends [P] ? ToOperation<Output, CanonicalInput, P> : (value: Output) => CanonicalInput;
```

Defined in: [packages/common/src/Type.ts:766](https://github.com/evoluhq/evolu/blob/f9257a718488bcc2c10afa2edb761c0eee5f5410/packages/common/src/Type.ts#L766)

Asserts and encodes an `Output` toward its canonical `Input`
representation.

`to` runs the complete encoding pipeline. Its first `.parent` stops at the
immediate parent Output, and each additional suffix stops one Type closer
to the root. Every entry point accepts this Type's `Output`.

### Example

```ts

const value = Int64.orThrow(42n);

assertEqual(Int64FromInt64String.to(value), "42");
```