API reference@evolu/commonType › ObjectType

Defined in: packages/common/src/Type.ts:3194

ObjectType extends Type with an additional props property for reflection.

Extends

  • Type<"Object", Readonly<ObjectT<Props>>, Readonly<ObjectInput<Props>>, ObjectError<{ [K in keyof Props]: InferError<Props[K]> }>, Readonly<ObjectParent<Props>>, ObjectError<{ [K in keyof Props]: InferParentError<Props[K]> }>>

Properties

[EvoluTypeSymbol]

readonly [EvoluTypeSymbol]: true;

Defined in: packages/common/src/Type.ts:410

Inherited from

Type.[EvoluTypeSymbol]


~standard

readonly ~standard: Props<Readonly<DrainOuterGeneric<{ [K in string | number | symbol]: ({ [K in string | number | symbol]: InferInput<Props[K]> } & { [K in string | number | symbol]?: Props[K] extends OptionalType<U> ? InferInput<U> : never })[K] }>>, Readonly<DrainOuterGeneric<{ [K in string | number | symbol]: ({ [K in string | number | symbol]: InferType<Props[K]> } & { [K in string | number | symbol]?: Props[K] extends OptionalType<U> ? InferType<U> : never })[K] }>>>;

Defined in: packages/common/src/Type.ts:4878

The Standard Schema properties.

Inherited from

Type.~standard


Error

Error: ObjectError<{ [K in string | number | symbol]: InferError<Props[K]> }>;

Defined in: packages/common/src/Type.ts:270

The specific error introduced by this Type.

Example

type StringError = typeof String.Error;

Inherited from

Type.Error


Errors

readonly Errors:
  | ObjectError<{ [K in string | number | symbol]: InferError<Props[K]> }>
| ObjectError<{ [K in string | number | symbol]: InferParentError<Props[K]> }>;

Defined in: packages/common/src/Type.ts:474

Example

type StringParentErrors = typeof String.Errors;

Inherited from

Type.Errors


from

readonly from: (value: Input) => Result<Readonly<DrainOuterGeneric<{ [K in string | number | symbol]: ({ [K in string | number | symbol]: InferType<Props[K]> } & { [K in string | number | symbol]?: (...)[(...)] extends OptionalType<(...)> ? InferType<(...)> : never })[K] }>>,
  | ObjectError<{ [K in string | number | symbol]: InferError<Props[K]> }>
| ObjectError<{ [K in string | number | symbol]: InferParentError<Props[K]> }>>;

Defined in: packages/common/src/Type.ts:285

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.from


fromParent

readonly fromParent: (value: Parent) => Result<Readonly<DrainOuterGeneric<{ [K in string | number | symbol]: ({ [K in string | number | symbol]: InferType<Props[K]> } & { [K in string | number | symbol]?: (...)[(...)] extends OptionalType<(...)> ? InferType<(...)> : never })[K] }>>, ObjectError<{ [K in string | number | symbol]: InferError<Props[K]> }>>;

Defined in: packages/common/src/Type.ts:387

Creates T from Parent type.

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

Inherited from

Type.fromParent


fromUnknown

readonly fromUnknown: (value: unknown) => Result<Readonly<DrainOuterGeneric<{ [K in string | number | symbol]: ({ [K in string | number | symbol]: InferType<Props[K]> } & { [K in string | number | symbol]?: (...)[(...)] extends OptionalType<(...)> ? InferType<(...)> : never })[K] }>>,
  | ObjectError<{ [K in string | number | symbol]: InferError<Props[K]> }>
| ObjectError<{ [K in string | number | symbol]: InferParentError<Props[K]> }>>;

Defined in: packages/common/src/Type.ts:379

Creates T from an unknown value.

This is useful when a value is unknown.

Inherited from

Type.fromUnknown


Input

Input: Readonly<
  DrainOuterGeneric<{
    [K in string | number | symbol]: ({
      [K in string | number | symbol]: InferInput<Props[K]>;
    } & {
      [K in string | number | symbol]?: Props[K] extends OptionalType<U>
        ? InferInput<U>
        : never;
    })[K];
  }>
>;

Defined in: packages/common/src/Type.ts:268

The type expected by from and fromUnknown.

Example

type StringInput = typeof String.Input;

Inherited from

Type.Input


is

readonly is: Refinement<unknown, Readonly<DrainOuterGeneric<{ [K in string | number | symbol]: ({ [K in string | number | symbol]: InferType<Props[K]> } & { [K in string | number | symbol]?: Props[K] extends OptionalType<U> ? InferType<U> : never })[K] }>>>;

Defined in: packages/common/src/Type.ts:408

A type guard that checks whether an unknown value satisfies the Type.

Example

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.is


name

readonly name: "Object";

Defined in: packages/common/src/Type.ts:276

Inherited from

Type.name


orNull

readonly orNull: (value: Input) =>
  | Readonly<DrainOuterGeneric<{ [K in string | number | symbol]: ({ [K in string | number | symbol]: InferType<Props[K]> } & { [K in string | number | symbol]?: (...)[(...)] extends OptionalType<(...)> ? InferType<(...)> : never })[K] }>>
  | null;

Defined in: packages/common/src/Type.ts:372

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

// 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.orNull


orThrow

readonly orThrow: (value: Input) => T;

Defined in: packages/common/src/Type.ts:341

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

// 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.orThrow


Parent

Parent: Readonly<
  DrainOuterGeneric<{
    [K in string | number | symbol]: ({
      [K in string | number | symbol]: InferParent<Props[K]>;
    } & {
      [K in string | number | symbol]?: Props[K] extends OptionalType<U>
        ? InferParent<U>
        : never;
    })[K];
  }>
>;

Defined in: packages/common/src/Type.ts:272

The parent type.

Example

type StringParent = typeof String.Parent;

Inherited from

Type.Parent


ParentError

ParentError: ObjectError<{
  [K in string | number | symbol]: InferParentError<Props[K]>;
}>;

Defined in: packages/common/src/Type.ts:274

The parent's error.

Example

type StringParentError = typeof String.ParentError;

Inherited from

Type.ParentError


props

readonly props: Props;

Defined in: packages/common/src/Type.ts:3202


Type

readonly Type: T;

Defined in: packages/common/src/Type.ts:421

The type this Type resolves to.

Example

type String = typeof String.Type;

Inherited from

Type.Type