Skip to content

egon-orm-workspace / egon-orm / CastResult

Type Alias: CastResult<T> ​

ts
type CastResult<T> = 
  | {
  data: T;
  success: true;
}
  | {
  message?: string;
  meta?: Readonly<Record<string, unknown>>;
  success: false;
};

Defined in: core/src/contracts/type.ts:24

The outcome of FieldType.cast: the cast value, or a failure with an optional message and metadata. A failure never throws and never carries the offending value.

message may contain {key} placeholders that are filled from meta, like every changeset error message. When message is omitted the changeset uses "is invalid".

Type Parameters ​

T ​

T

Example ​

ts
const good: CastResult<number> = { success: true, data: 42 };
const bad: CastResult<number> = { success: false, message: "must be a whole number", meta: { kind: "integer" } };