[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) › SetType

Defined in: [packages/common/src/Type.ts:2651](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/common/src/Type.ts#L2651)

SetType extends Type with an additional `element` property for reflection.

## Extends

- [`Type`](https://evolu.dev/docs/api-reference/common/Type/interfaces/Type)\<`"Set"`, `ReadonlySet`\<[`InferType`](https://evolu.dev/docs/api-reference/common/Type/type-aliases/InferType)\<`ElementType`\>\>, `ReadonlySet`\<[`InferInput`](https://evolu.dev/docs/api-reference/common/Type/type-aliases/InferInput)\<`ElementType`\>\>, [`SetError`](https://evolu.dev/docs/api-reference/common/Type/interfaces/SetError)\<[`InferError`](https://evolu.dev/docs/api-reference/common/Type/type-aliases/InferError)\<`ElementType`\>\>, `ReadonlySet`\<[`InferParent`](https://evolu.dev/docs/api-reference/common/Type/type-aliases/InferParent)\<`ElementType`\>\>, [`SetError`](https://evolu.dev/docs/api-reference/common/Type/interfaces/SetError)\<[`InferParentError`](https://evolu.dev/docs/api-reference/common/Type/type-aliases/InferParentError)\<`ElementType`\>\>\>

## Properties

<a id="evolutypesymbol"></a>

### \[EvoluTypeSymbol\]

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

Defined in: [packages/common/src/Type.ts:410](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/common/src/Type.ts#L410)

#### Inherited from

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

---

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

### ~standard

```ts
readonly ~standard: Props<ReadonlySet<InferInput<ElementType>>, ReadonlySet<InferType<ElementType>>>;
```

Defined in: [packages/common/src/Type.ts:4878](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/common/src/Type.ts#L4878)

The Standard Schema properties.

#### Inherited from

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

---

<a id="element"></a>

### element

```ts
readonly element: ElementType;
```

Defined in: [packages/common/src/Type.ts:2659](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/common/src/Type.ts#L2659)

---

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

### Error

```ts
Error: SetError<InferError<ElementType>>;
```

Defined in: [packages/common/src/Type.ts:270](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/common/src/Type.ts#L270)

The specific error introduced by this Type.

### Example

```ts
type StringError = typeof String.Error;
```

#### Inherited from

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

---

<a id="errors"></a>

### Errors

```ts
readonly Errors:
  | SetError<InferError<ElementType>>
| SetError<InferParentError<ElementType>>;
```

Defined in: [packages/common/src/Type.ts:474](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/common/src/Type.ts#L474)

### Example

```ts
type StringParentErrors = typeof String.Errors;
```

#### Inherited from

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

---

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

### from

```ts
readonly from: (value: ReadonlySet) => Result<ReadonlySet<InferType<ElementType>>,
  | SetError<InferError<ElementType>>
| SetError<InferParentError<ElementType>>>;
```

Defined in: [packages/common/src/Type.ts:285](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/common/src/Type.ts#L285)

Creates `T` from an `Input` value.

This is useful when we have a typed value.

`from` is a typed alias of `fromUnknown`.

#### Inherited from

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

---

<a id="fromparent"></a>

### fromParent

```ts
readonly fromParent: (value: ReadonlySet) => Result<ReadonlySet<InferType<ElementType>>, SetError<InferError<ElementType>>>;
```

Defined in: [packages/common/src/Type.ts:387](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/common/src/Type.ts#L387)

Creates `T` from `Parent` type.

This function skips parent Types validations when we have already partially
validated value.

#### Inherited from

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

---

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

### fromUnknown

```ts
readonly fromUnknown: (value: unknown) => Result<ReadonlySet<InferType<ElementType>>,
  | SetError<InferError<ElementType>>
| SetError<InferParentError<ElementType>>>;
```

Defined in: [packages/common/src/Type.ts:379](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/common/src/Type.ts#L379)

Creates `T` from an unknown value.

This is useful when a value is unknown.

#### Inherited from

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

---

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

### Input

```ts
Input: ReadonlySet<InferInput<ElementType>>;
```

Defined in: [packages/common/src/Type.ts:268](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/common/src/Type.ts#L268)

The type expected by `from` and `fromUnknown`.

### Example

```ts
type StringInput = typeof String.Input;
```

#### Inherited from

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

---

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

### is

```ts
readonly is: Refinement<unknown, ReadonlySet<InferType<ElementType>>>;
```

Defined in: [packages/common/src/Type.ts:408](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/common/src/Type.ts#L408)

A **type guard** that checks whether an unknown value satisfies the
[Type](https://evolu.dev/docs/api-reference/common/Type/interfaces/Type).

### Example

```ts
const value: unknown = "hello";
if (String.is(value)) {
  // TypeScript now knows `value` is a `string` here.
  console.log("This is a valid string!");
}

const strings: unknown[] = [1, "hello", true, "world"];
const filteredStrings = strings.filter(String.is);

console.log(filteredStrings); // ["hello", "world"]
```

#### Inherited from

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

---

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

### name

```ts
readonly name: "Set";
```

Defined in: [packages/common/src/Type.ts:276](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/common/src/Type.ts#L276)

#### Inherited from

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

---

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

### orNull

```ts
readonly orNull: (value: ReadonlySet) =>
  | ReadonlySet<InferType<ElementType>>
  | null;
```

Defined in: [packages/common/src/Type.ts:372](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/common/src/Type.ts#L372)

Creates `T` from an `Input` value, returning `null` if validation fails.

This is a convenience method that combines `from` with `getOrNull`.

**When to use:**

- When you need to convert a validation result to a nullable value
- When the error is not important and you just want the value or nothing

### Example

```ts
// Good: Optional user input
const age = PositiveInt.orNull(userInput);
if (age != null) {
  console.log("Valid age:", age);
}

// Good: Default fallback
const maxRetries = PositiveInt.orNull(config.retries) ?? 3;

// Avoid: When you need to know why validation failed (use `from` instead)
const result = PositiveInt.from(userInput);
if (!result.ok) {
  console.error(formatPositiveError(result.error));
}
```

#### Inherited from

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

---

<a id="orthrow"></a>

### orThrow

```ts
readonly orThrow: (value: ReadonlySet) => ReadonlySet;
```

Defined in: [packages/common/src/Type.ts:341](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/common/src/Type.ts#L341)

Creates `T` from an `Input` value, throwing an error if validation fails.

Use this where failure should crash the current flow instead of being
handled locally.

Throws an Error with the Type validation error in its `cause` property,
making it debuggable while avoiding the need for custom error messages.

This is a convenience method that combines `from` with `getOrThrow`.

**When to use:**

- Application startup or composition-root setup where errors must stop the
  program immediately. In Evolu apps, errors are handled by
  platform-specific `createRun` adapters at the app boundary.
- Module-level constants
- Test setup with values that are expected to be valid
- As an alternative to assertions when the Type error in the thrown Error's
  `cause` provides sufficient debugging information

Prefer `from` in ordinary application logic where the caller can recover,
show validation errors, or choose a different flow.

For clearer test failure messages on invalid input, use Vitest
`schemaMatching` + `assert` with `.is()`.

### Example

```ts
// Good: Known valid constant
const maxRetries = PositiveInt.orThrow(3);

// Good: App configuration that should crash on invalid values
const appName = Name.orThrow("MyApp");

// Good: Instead of assert when Type error is clear enough
// Context makes it obvious: count increments from non-negative value
const currentCount = counts.get(id) ?? 0;
const newCount = PositiveInt.orThrow(currentCount + 1);

// Good: Test setup with known valid values
const testUser = User.orThrow({ name: "Alice", age: 30 });

// Avoid: User input (use `from` instead)
const userAge = PositiveInt.orThrow(userInput); // Could crash!

// Better: Handle user input gracefully
const ageResult = PositiveInt.from(userInput);
if (!ageResult.ok) {
  // Handle validation error
}
```

#### Inherited from

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

---

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

### Parent

```ts
Parent: ReadonlySet<InferParent<ElementType>>;
```

Defined in: [packages/common/src/Type.ts:272](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/common/src/Type.ts#L272)

The parent type.

### Example

```ts
type StringParent = typeof String.Parent;
```

#### Inherited from

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

---

<a id="parenterror"></a>

### ParentError

```ts
ParentError: SetError<InferParentError<ElementType>>;
```

Defined in: [packages/common/src/Type.ts:274](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/common/src/Type.ts#L274)

The parent's error.

### Example

```ts
type StringParentError = typeof String.ParentError;
```

#### Inherited from

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

---

<a id="type"></a>

### Type

```ts
readonly Type: ReadonlySet;
```

Defined in: [packages/common/src/Type.ts:421](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/common/src/Type.ts#L421)

The type this Type resolves to.

### Example

```ts
type String = typeof String.Type;
```

#### Inherited from

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