Skip to content

Schema

509 exports Added in v1.0.0 Source

Accessor

exitSchema

Added in v3.10.0 Source

Signature

declare function exitSchema<SA, SI, FA, FI, R>(
  self: WithResult<SA, SI, FA, FI, R>,
): Schema<Exit<SA, FA>, ExitEncoded<SI, FI, unknown>, R>;

failureSchema

Added in v3.10.0 Source

Signature

declare function failureSchema<SA, SI, FA, FI, R>(
  self: WithResult<SA, SI, FA, FI, R>,
): Schema<FA, FI, R>;

Signature

declare function serializableSchema<A, I, R>(self: Serializable<A, I, R>): Schema<A, I, R>;

successSchema

Added in v3.10.0 Source

Signature

declare function successSchema<SA, SI, FA, FI, R>(
  self: WithResult<SA, SI, FA, FI, R>,
): Schema<SA, SI, R>;

Annotations

Annotable

Added in v3.10.0 Source

Annotable interface

Added in v3.10.0 Source

Signature

interface Annotable<Self extends Schema<A, I, R>, A, I = A, R = never> extends Schema<A, I, R> {
  annotations(annotations: GenericSchema<A>): Self;
}

AnnotableClass interface

Added in v3.10.0 Source

Signature

interface AnnotableClass<Self extends Schema<A, I, R>, A, I = A, R = never> extends Annotable<
  Self,
  A,
  I,
  R
> {
  constructor(_: never);
}

annotations

Added in v3.10.0 Source

Merges a set of new annotations with existing ones, potentially overwriting any duplicates.

Signature

declare const annotations: {
  <S extends All>(annotations: GenericSchema<Type<S>>): (self: S) => ReturnType<S["annotations"]>;
  <S extends All>(self: S, annotations: GenericSchema<Type<S>>): ReturnType<S["annotations"]>;
};

Annotations

Added in v3.10.0 Source

Api Interface

AnnotableDeclare interface

Added in v3.13.3 Source

Signature

interface AnnotableDeclare<
  Self extends declare<A, I, P, R>,
  A,
  I = A,
  P extends ReadonlyArray<Schema.All> = readonly [],
  R = Schema.Context<P[number]>,
> extends declare<A, I, P, R> {
  constructor(_: never);
  annotations(annotations: Schema<A>): Self;
}

Array$ interface

Added in v3.10.0 Source

Signature

interface Array$<Value extends Schema.Any> extends TupleType<[], [Value]> {
  constructor(_: never);
  readonly value: Value;
  annotations(annotations: Schema<readonly Array<Type<Value>>>): Array$<Value>;
}

ArrayEnsure interface

Added in v3.10.0 Source

Signature

interface ArrayEnsure<Value extends Schema.Any> extends transform<
  Union<[Value, Array$<Value>]>,
  Array$<SchemaClass<Schema.Type<Value>>>
> {
  constructor(_: never);
}

brand interface

Added in v3.10.0 Source

Signature

interface brand<S extends Schema.Any, B extends string | symbol> extends BrandSchema<
  Schema.Type<S> & Brand<B>,
  Schema.Encoded<S>,
  Schema.Context<S>
> {
  constructor(_: never);
  readonly from: S;
  annotations(annotations: Schema<Type<S> & Brand<B>>): brand<S, B>;
}

Cause interface

Added in v3.10.0 Source

Signature

interface Cause<E extends Schema.All, D extends Schema.All> extends transform<
  SchemaClass<
    CauseEncoded<Schema.Type<E>, Schema.Type<Defect>>,
    CauseEncoded<Schema.Encoded<E>, Schema.Encoded<Defect>>,
    Schema.Context<E> | Schema.Context<D>
  >,
  CauseFromSelf<SchemaClass<Schema.Type<E>>, SchemaClass<Schema.Type<D>>>
> {
  constructor(_: never);
}

CauseFromSelf interface

Added in v3.10.0 Source

Signature

interface CauseFromSelf<E extends Schema.All, D extends Schema.All> extends AnnotableDeclare<
  CauseFromSelf<E, D>,
  cause_.Cause<Schema.Type<E>>,
  cause_.Cause<Schema.Encoded<E>>,
  [E, D]
> {
  constructor(_: never);
}

Chunk interface

Added in v3.10.0 Source

Signature

interface Chunk<Value extends Schema.Any> extends transform<
  Array$<Value>,
  ChunkFromSelf<SchemaClass<Schema.Type<Value>>>
> {
  constructor(_: never);
}

ChunkFromSelf interface

Added in v3.10.0 Source

Signature

interface ChunkFromSelf<Value extends Schema.Any> extends AnnotableDeclare<
  ChunkFromSelf<Value>,
  chunk_.Chunk<Schema.Type<Value>>,
  chunk_.Chunk<Schema.Encoded<Value>>,
  [Value]
> {
  constructor(_: never);
}

Class interface

Added in v3.10.0 Source

Signature

interface Class<Self, Fields extends Struct.Fields, I, R, C, Inherited, Proto> extends Schema<Self, Simplify<I>, R> {
  constructor(props: RequiredKeys<C> extends never ? void | { [K in string | number | symbol]: C[K] } : { [K in string | number | symbol]: C[K] }, options?: MakeOptions);
  readonly ast: Transformation;
  readonly fields: { [K in string | number | symbol]: Fields[K] };
  readonly identifier: string;
  annotations(annotations: Schema<Self>): SchemaClass<Self, { [K in string | number | symbol]: I[K] }, R>;
  extend<Extended = never>(identifier: string): <NewFields extends Fields>(fields: NewFields | HasFields<NewFields>, annotations?: ClassAnnotations<Extended, { [K in string | number | symbol]: Type<Fields & NewFields>[K] }>) => [Extended] extends [never] ? "Missing `Self` generic - use `class Self extends Base.extend<Self>()({ ... })`" : Class<Extended, Fields & NewFields, I & { [K in string | number | symbol]: Encoded<NewFields[K]> } & { [K in string | number | symbol]: Encoded<NewFields[K]> }, R | Context<NewFields[keyof NewFields]>, C & Constructor<NewFields>, Self, Proto>;
  make<C extends (...args: Array<any>) => any>(this: C, ...args: ConstructorParameters<C>): InstanceType<C>;
  transformOrFail<Transformed = never>(identifier: string): <NewFields extends Fields, R2, R3>(fields: NewFields, options: {
    readonly decode: (input: { [K in string | number | symbol]: Type<Fields>[K] }, options: ParseOptions, ast: Transformation) => Effect<{ [K in string | number | symbol]: Type<Fields & NewFields>[K] }, ParseIssue, R2>;
    readonly encode: (input: { [K in string | number | symbol]: Type<Fields & NewFields>[K] }, options: ParseOptions, ast: Transformation) => Effect<Type<Fields>, ParseIssue, R3>;
  }, annotations?: ClassAnnotations<Transformed, { [K in string | number | symbol]: Type<Fields & NewFields>[K] }>) => [Transformed] extends [never] ? "Missing `Self` generic - use `class Self extends Base.transformOrFail<Self>()({ ... })`" : Class<Transformed, Fields & NewFields, I, R | R2 | R3 | Context<NewFields[keyof NewFields]>, C & Constructor<NewFields>, Self, Proto>;
  transformOrFailFrom<Transformed = never>(identifier: string): <NewFields extends Fields, R2, R3>(fields: NewFields, options: {
    readonly decode: (input: { [K in string | number | symbol]: I[K] }, options: ParseOptions, ast: Transformation) => Effect<{ [K in string | number | symbol]: I & { [K in string | number | symbol]: Encoded<NewFields[K]> } & { [K in string | number | symbol]: Encoded<...[...]> }[K] }, ParseIssue, R2>;
    readonly encode: (input: { [K in string | number | symbol]: I & { [K in string | number | symbol]: Encoded<NewFields[K]> } & { [K in string | number | symbol]: Encoded<NewFields[K]> }[K] }, options: ParseOptions, ast: Transformation) => Effect<I, ParseIssue, R3>;
  }, annotations?: ClassAnnotations<Transformed, { [K in string | number | symbol]: Type<Fields & NewFields>[K] }>) => [Transformed] extends [never] ? "Missing `Self` generic - use `class Self extends Base.transformOrFailFrom<Self>()({ ... })`" : Class<Transformed, Fields & NewFields, I, R | R2 | R3 | Context<NewFields[keyof NewFields]>, C & Constructor<NewFields>, Self, Proto>;
}

Data interface

Added in v3.13.3 Source

Signature

interface Data<Value extends Schema.Any> extends transform<
  Value,
  DataFromSelf<SchemaClass<Schema.Type<Value>>>
> {
  constructor(_: never);
}

DataFromSelf interface

Added in v3.13.3 Source

Signature

interface DataFromSelf<Value extends Schema.Any> extends AnnotableDeclare<
  DataFromSelf<Value>,
  Schema.Type<Value>,
  Schema.Encoded<Value>,
  [Value]
> {
  constructor(_: never);
}

declare interface

Added in v3.13.3 Source

Signature

interface declare<
  A,
  I = A,
  P extends ReadonlyArray<Schema.All> = readonly [],
  R = Schema.Context<P[number]>,
> extends AnnotableClass<declare<A, I, P, R>, A, I, R> {
  constructor(_: never);
  readonly typeParameters: Readonly<P>;
}

Either interface

Added in v3.10.0 Source

Signature

interface Either<Right extends Schema.All, Left extends Schema.All> extends transform<
  Union<
    [
      Struct<{
        _tag: Literal<["Right"]>;
        right: Right;
      }>,
      Struct<{
        _tag: Literal<["Left"]>;
        left: Left;
      }>,
    ]
  >,
  EitherFromSelf<SchemaClass<Schema.Type<Right>>, SchemaClass<Schema.Type<Left>>>
> {
  constructor(_: never);
}

EitherFromSelf interface

Added in v3.10.0 Source

Signature

interface EitherFromSelf<R extends Schema.All, L extends Schema.All> extends AnnotableDeclare<
  EitherFromSelf<R, L>,
  either_.Either<Schema.Type<R>, Schema.Type<L>>,
  either_.Either<Schema.Encoded<R>, Schema.Encoded<L>>,
  [R, L]
> {
  constructor(_: never);
}

EitherFromUnion interface

Added in v3.10.0 Source

Signature

interface EitherFromUnion<Right extends Schema.All, Left extends Schema.All> extends transform<
  Union<
    [
      transform<
        Right,
        Struct<{
          _tag: Literal<["Right"]>;
          right: SchemaClass<Schema.Type<Right>>;
        }>
      >,
      transform<
        Left,
        Struct<{
          _tag: Literal<["Left"]>;
          right: SchemaClass<Schema.Type<Left>>;
        }>
      >,
    ]
  >,
  EitherFromSelf<SchemaClass<Schema.Type<Right>>, SchemaClass<Schema.Type<Left>>>
> {
  constructor(_: never);
}

Enums interface

Added in v3.10.0 Source

Signature

interface Enums<A extends EnumsDefinition> extends AnnotableClass<Enums<A>, A[keyof A]> {
  constructor(_: never);
  readonly enums: A;
}

Exit interface

Added in v3.10.0 Source

Signature

interface Exit<A extends Schema.All, E extends Schema.All, D extends Schema.All> extends transform<
  Union<
    [
      Struct<{
        _tag: Literal<["Failure"]>;
        cause: SchemaClass<
          CauseEncoded<Schema.Type<E>, Schema.Type<D>>,
          CauseEncoded<Schema.Encoded<E>, Schema.Encoded<D>>,
          Schema.Context<E> | Schema.Context<D>
        >;
      }>,
      Struct<{
        _tag: Literal<["Success"]>;
        value: A;
      }>,
    ]
  >,
  ExitFromSelf<
    SchemaClass<Schema.Type<A>>,
    SchemaClass<Schema.Type<E>>,
    SchemaClass<Schema.Type<D>>
  >
> {
  constructor(_: never);
}

ExitFromSelf interface

Added in v3.10.0 Source

Signature

interface ExitFromSelf<
  A extends Schema.All,
  E extends Schema.All,
  D extends Schema.All,
> extends AnnotableDeclare<
  ExitFromSelf<A, E, D>,
  exit_.Exit<Schema.Type<A>, Schema.Type<E>>,
  exit_.Exit<Schema.Encoded<A>, Schema.Encoded<E>>,
  [A, E, D]
> {
  constructor(_: never);
}

extend interface

Added in v3.10.0 Source

Signature

interface extend<Self extends Schema.Any, That extends Schema.Any> extends AnnotableClass<
  extend<Self, That>,
  Schema.Type<Self> & Schema.Type<That>,
  Schema.Encoded<Self> & Schema.Encoded<That>,
  Schema.Context<Self> | Schema.Context<That>
> {
  constructor(_: never);
}

filter interface

Added in v3.10.0 Source

Signature

interface filter<From extends Schema.Any> extends refine<Schema.Type<From>, From> {
  constructor(_: never);
}

filterEffect interface

Added in v3.10.0 Source

Signature

interface filterEffect<S extends Schema.Any, FD = never> extends transformOrFail<
  S,
  SchemaClass<Schema.Type<S>>,
  FD
> {
  constructor(_: never);
}

HashMap interface

Added in v3.10.0 Source

Signature

interface HashMap<K extends Schema.Any, V extends Schema.Any> extends transform<
  Array$<Tuple2<K, V>>,
  HashMapFromSelf<SchemaClass<Schema.Type<K>>, SchemaClass<Schema.Type<V>>>
> {
  constructor(_: never);
}

HashMapFromSelf interface

Added in v3.10.0 Source

Signature

interface HashMapFromSelf<K extends Schema.Any, V extends Schema.Any> extends AnnotableDeclare<
  HashMapFromSelf<K, V>,
  hashMap_.HashMap<Schema.Type<K>, Schema.Type<V>>,
  hashMap_.HashMap<Schema.Encoded<K>, Schema.Encoded<V>>,
  [K, V]
> {
  constructor(_: never);
}

HashSet interface

Added in v3.10.0 Source

Signature

interface HashSet<Value extends Schema.Any> extends transform<
  Array$<Value>,
  HashSetFromSelf<SchemaClass<Schema.Type<Value>>>
> {
  constructor(_: never);
}

HashSetFromSelf interface

Added in v3.10.0 Source

Signature

interface HashSetFromSelf<Value extends Schema.Any> extends AnnotableDeclare<
  HashSetFromSelf<Value>,
  hashSet_.HashSet<Schema.Type<Value>>,
  hashSet_.HashSet<Schema.Encoded<Value>>,
  [Value]
> {
  constructor(_: never);
}

instanceOf interface

Added in v3.10.0 Source

Signature

interface instanceOf<A> extends AnnotableDeclare<instanceOf<A>, A> {
  constructor(_: never);
}

List interface

Added in v3.10.0 Source

Signature

interface List<Value extends Schema.Any> extends transform<
  Array$<Value>,
  ListFromSelf<SchemaClass<Schema.Type<Value>>>
> {
  constructor(_: never);
}

ListFromSelf interface

Added in v3.10.0 Source

Signature

interface ListFromSelf<Value extends Schema.Any> extends AnnotableDeclare<
  ListFromSelf<Value>,
  list_.List<Schema.Type<Value>>,
  list_.List<Schema.Encoded<Value>>,
  [Value]
> {
  constructor(_: never);
}

Literal interface

Added in v3.10.0 Source

Signature

interface Literal<
  Literals extends array_.NonEmptyReadonlyArray<AST.LiteralValue>,
> extends AnnotableClass<Literal<Literals>, Literals[number]> {
  constructor(_: never);
  readonly literals: Readonly<Literals>;
}

Map$ interface

Added in v3.10.0 Source

Signature

interface Map$<K extends Schema.Any, V extends Schema.Any> extends transform<
  Array$<Tuple2<K, V>>,
  MapFromSelf<SchemaClass<Schema.Type<K>>, SchemaClass<Schema.Type<V>>>
> {
  constructor(_: never);
}

MapFromSelf interface

Added in v3.10.0 Source

Signature

interface MapFromSelf<K extends Schema.Any, V extends Schema.Any> extends AnnotableDeclare<
  MapFromSelf<K, V>,
  Map<Schema.Type<K>, Schema.Type<V>>,
  ReadonlyMap<Schema.Encoded<K>, Schema.Encoded<V>>,
  [K, V]
> {
  constructor(_: never);
}

mutable interface

Added in v3.10.0 Source

Signature

interface mutable<S extends Schema.Any> extends AnnotableClass<
  mutable<S>,
  SimplifyMutable<Schema.Type<S>>,
  SimplifyMutable<Schema.Encoded<S>>,
  Schema.Context<S>
> {
  constructor(_: never);
}

NonEmptyArray interface

Added in v3.10.0 Source

Signature

interface NonEmptyArray<Value extends Schema.Any> extends AnnotableClass<
  NonEmptyArray<Value>,
  array_.NonEmptyReadonlyArray<Schema.Type<Value>>,
  array_.NonEmptyReadonlyArray<Schema.Encoded<Value>>,
  Schema.Context<Value>
> {
  constructor(_: never);
  readonly elements: readonly [Value];
  readonly rest: readonly [Value];
  readonly value: Value;
}

NonEmptyArrayEnsure interface

Added in v3.10.0 Source

Signature

interface NonEmptyArrayEnsure<Value extends Schema.Any> extends transform<
  Union<[Value, NonEmptyArray<Value>]>,
  NonEmptyArray<SchemaClass<Schema.Type<Value>>>
> {
  constructor(_: never);
}

NonEmptyChunk interface

Added in v3.10.0 Source

Signature

interface NonEmptyChunk<Value extends Schema.Any> extends transform<
  NonEmptyArray<Value>,
  NonEmptyChunkFromSelf<SchemaClass<Schema.Type<Value>>>
> {
  constructor(_: never);
}

NonEmptyChunkFromSelf interface

Added in v3.10.0 Source

Signature

interface NonEmptyChunkFromSelf<Value extends Schema.Any> extends AnnotableDeclare<
  NonEmptyChunkFromSelf<Value>,
  chunk_.NonEmptyChunk<Schema.Type<Value>>,
  chunk_.NonEmptyChunk<Schema.Encoded<Value>>,
  [Value]
> {
  constructor(_: never);
}

NullishOr interface

Added in v3.10.0 Source

Signature

interface NullishOr<S extends Schema.All> extends Union<[S, typeof Null, typeof Undefined]> {
  constructor(_: never);
  annotations(annotations: Schema<Type<S> | null | undefined>): NullishOr<S>;
}

NullOr interface

Added in v3.10.0 Source

Signature

interface NullOr<S extends Schema.All> extends Union<[S, typeof Null]> {
  constructor(_: never);
  annotations(annotations: Schema<Type<S> | null>): NullOr<S>;
}

Option interface

Added in v3.10.0 Source

Signature

interface Option<Value extends Schema.Any> extends transform<
  Union<
    [
      Struct<{
        _tag: Literal<["None"]>;
      }>,
      Struct<{
        _tag: Literal<["Some"]>;
        value: Value;
      }>,
    ]
  >,
  OptionFromSelf<SchemaClass<Schema.Type<Value>>>
> {
  constructor(_: never);
}

optional interface

Added in v3.10.0 Source

Signature

interface optional<S extends Schema.All> extends PropertySignature<
  "?:",
  Schema.Type<S> | undefined,
  never,
  "?:",
  Schema.Encoded<S> | undefined,
  false,
  Schema.Context<S>
> {
  readonly from: S;
  annotations(annotations: Annotations<Type<S> | undefined>): optional<S>;
}

optionalWith interface

Added in v3.10.0 Source

Signature

interface optionalWith<S extends Schema.All, Options> extends PropertySignature<
  Types.Has<Options, "as" | "default"> extends true ? ":" : "?:",
  Types.Has<Options, "as"> extends true
    ? option_.Option<Schema.Type<S>>
    : Schema.Type<S> | Types.Has<Options, "as" | "default" | "exact"> extends true
      ? never
      : undefined,
  never,
  "?:",
  Schema.Encoded<S> | Types.Has<Options, "nullable"> extends true
    ? null
    : never | Types.Has<Options, "exact"> extends true
      ? never
      : undefined,
  Types.Has<Options, "default">,
  Schema.Context<S>
> {
  readonly from: S;
  annotations(
    annotations: Annotations<
      Has<Options, "as"> extends true
        ? Option<Type<S>>
        : Type<S> | Has<Options, "default" | "as" | "exact"> extends true
          ? never
          : undefined
    >,
  ): optionalWith<S, Options>;
}

OptionFromNullishOr interface

Added in v3.10.0 Source

Signature

interface OptionFromNullishOr<Value extends Schema.Any> extends transform<
  NullishOr<Value>,
  OptionFromSelf<SchemaClass<Schema.Type<Value>>>
> {
  constructor(_: never);
}

OptionFromNullOr interface

Added in v3.10.0 Source

Signature

interface OptionFromNullOr<Value extends Schema.Any> extends transform<
  NullOr<Value>,
  OptionFromSelf<SchemaClass<Schema.Type<Value>>>
> {
  constructor(_: never);
}

OptionFromSelf interface

Added in v3.10.0 Source

Signature

interface OptionFromSelf<Value extends Schema.Any> extends AnnotableDeclare<
  OptionFromSelf<Value>,
  option_.Option<Schema.Type<Value>>,
  option_.Option<Schema.Encoded<Value>>,
  [Value]
> {
  constructor(_: never);
}

OptionFromUndefinedOr interface

Added in v3.10.0 Source

Signature

interface OptionFromUndefinedOr<Value extends Schema.Any> extends transform<
  UndefinedOr<Value>,
  OptionFromSelf<SchemaClass<Schema.Type<Value>>>
> {
  constructor(_: never);
}

ReadonlyMap$ interface

Added in v3.10.0 Source

Signature

interface ReadonlyMap$<K extends Schema.Any, V extends Schema.Any> extends transform<
  Array$<Tuple2<K, V>>,
  ReadonlyMapFromSelf<SchemaClass<Schema.Type<K>>, SchemaClass<Schema.Type<V>>>
> {
  constructor(_: never);
}

ReadonlyMapFromSelf interface

Added in v3.10.0 Source

Signature

interface ReadonlyMapFromSelf<K extends Schema.Any, V extends Schema.Any> extends AnnotableDeclare<
  ReadonlyMapFromSelf<K, V>,
  ReadonlyMap<Schema.Type<K>, Schema.Type<V>>,
  ReadonlyMap<Schema.Encoded<K>, Schema.Encoded<V>>,
  [K, V]
> {
  constructor(_: never);
}

ReadonlySet$ interface

Added in v3.10.0 Source

Signature

interface ReadonlySet$<Value extends Schema.Any> extends transform<
  Array$<Value>,
  ReadonlySetFromSelf<SchemaClass<Schema.Type<Value>>>
> {
  constructor(_: never);
}

ReadonlySetFromSelf interface

Added in v3.10.0 Source

Signature

interface ReadonlySetFromSelf<Value extends Schema.Any> extends AnnotableDeclare<
  ReadonlySetFromSelf<Value>,
  ReadonlySet<Schema.Type<Value>>,
  ReadonlySet<Schema.Encoded<Value>>,
  [Value]
> {
  constructor(_: never);
}

Record$ interface

Added in v3.10.0 Source

Signature

interface Record$<K extends Schema.All, V extends Schema.All> extends AnnotableClass<
  Record$<K, V>,
  { [P in Schema.Type<K>]: Schema.Type<V> },
  { [P in Schema.Encoded<K>]: Schema.Encoded<V> },
  Schema.Context<K> | Schema.Context<V>
> {
  constructor(_: never);
  readonly fields: {};
  readonly key: K;
  readonly records: readonly [
    {
      readonly key: K;
      readonly value: V;
    },
  ];
  readonly value: V;
  annotations(annotations: Schema<{ [P in any]: Type<V> }>): Record$<K, V>;
  make(props: void | { [P in any]: Type<V> }, options?: MakeOptions): { [P in any]: Type<V> };
}

Redacted interface

Added in v3.10.0 Source

Signature

interface Redacted<Value extends Schema.Any> extends transform<
  Value,
  RedactedFromSelf<SchemaClass<Schema.Type<Value>>>
> {
  constructor(_: never);
}

RedactedFromSelf interface

Added in v3.10.0 Source

Signature

interface RedactedFromSelf<Value extends Schema.Any> extends AnnotableDeclare<
  RedactedFromSelf<Value>,
  redacted_.Redacted<Schema.Type<Value>>,
  redacted_.Redacted<Schema.Encoded<Value>>,
  [Value]
> {
  constructor(_: never);
}

refine interface

Added in v3.10.0 Source

Signature

interface refine<A, From extends Schema.Any> extends AnnotableClass<
  refine<A, From>,
  A,
  Schema.Encoded<From>,
  Schema.Context<From>
> {
  constructor(_: never);
  readonly [RefineSchemaId]: From;
  readonly filter: (a: Type<From>, options: ParseOptions, self: Refinement) => Option<ParseIssue>;
  readonly from: From;
  make(a: Type<From>, options?: MakeOptions): A;
}

Set$ interface

Added in v3.10.0 Source

Signature

interface Set$<Value extends Schema.Any> extends transform<
  Array$<Value>,
  SetFromSelf<SchemaClass<Schema.Type<Value>>>
> {
  constructor(_: never);
}

SetFromSelf interface

Added in v3.10.0 Source

Signature

interface SetFromSelf<Value extends Schema.Any> extends AnnotableDeclare<
  SetFromSelf<Value>,
  Set<Schema.Type<Value>>,
  ReadonlySet<Schema.Encoded<Value>>,
  [Value]
> {
  constructor(_: never);
}

SortedSet interface

Added in v3.10.0 Source

Signature

interface SortedSet<Value extends Schema.Any> extends transform<
  Array$<Value>,
  SortedSetFromSelf<SchemaClass<Schema.Type<Value>>>
> {
  constructor(_: never);
}

SortedSetFromSelf interface

Added in v3.10.0 Source

Signature

interface SortedSetFromSelf<Value extends Schema.Any> extends AnnotableDeclare<
  SortedSetFromSelf<Value>,
  sortedSet_.SortedSet<Schema.Type<Value>>,
  sortedSet_.SortedSet<Schema.Encoded<Value>>,
  [Value]
> {
  constructor(_: never);
}

Struct interface

Added in v3.10.0 Source

Signature

interface Struct<Fields extends Struct.Fields> extends AnnotableClass<Struct<Fields>, Simplify<Struct.Type<Fields>>, Simplify<Struct.Encoded<Fields>>, Struct.Context<Fields>> {
  constructor(_: never);
  readonly fields: Readonly<Fields>;
  readonly records: readonly [];
  annotations(annotations: Schema<{ [K in string | number | symbol]: Type<Fields>[K] }>): Struct<Fields>;
  make(props: RequiredKeys<Constructor<Fields>> extends never ? void | { [K in string | number | symbol]: Constructor<Fields>[K] } : { [K in string | number | symbol]: Constructor<Fields>[K] }, options?: MakeOptions): { [K in string | number | symbol]: Type<Fields>[K] };
  omit<Keys extends readonly Array<keyof Fields>>(...keys: Keys): Struct<{ [K in string | number | symbol]: Omit<Fields, Keys[number]>[K] }>;
  pick<Keys extends readonly Array<keyof Fields>>(...keys: Keys): Struct<{ [K in string | number | symbol]: Pick<Fields, Keys[number]>[K] }>;
}

suspend interface

Added in v3.10.0 Source

Signature

interface suspend<A, I, R> extends AnnotableClass<suspend<A, I, R>, A, I, R> {
  constructor(_: never);
}

tag interface

Added in v3.10.0 Source

Signature

interface tag<Tag extends AST.LiteralValue> extends PropertySignature<
  ":",
  Tag,
  never,
  ":",
  Tag,
  true,
  never
> {}

TaggedClass interface

Added in v3.10.0 Source

Signature

interface TaggedClass<Self, Tag extends string, Fields extends Struct.Fields> extends Class<
  Self,
  Fields,
  Struct.Encoded<Fields>,
  Struct.Context<Fields>,
  Struct.Constructor<Omit<Fields, "_tag">>,
  {},
  {}
> {
  constructor(
    props: RequiredKeys<Constructor<Omit<Fields, "_tag">>> extends never
      ? void | { [K in string | number | symbol]: Constructor<Omit<Fields, "_tag">>[K] }
      : { [K in string | number | symbol]: Constructor<Omit<Fields, "_tag">>[K] },
    options?: MakeOptions,
  );
  readonly _tag: Tag;
}

TaggedErrorClass interface

Added in v3.10.0 Source

Signature

interface TaggedErrorClass<Self, Tag extends string, Fields extends Struct.Fields> extends Class<
  Self,
  Fields,
  Struct.Encoded<Fields>,
  Struct.Context<Fields>,
  Struct.Constructor<Omit<Fields, "_tag">>,
  {},
  cause_.YieldableError
> {
  constructor(
    props: RequiredKeys<Constructor<Omit<Fields, "_tag">>> extends never
      ? void | { [K in string | number | symbol]: Constructor<Omit<Fields, "_tag">>[K] }
      : { [K in string | number | symbol]: Constructor<Omit<Fields, "_tag">>[K] },
    options?: MakeOptions,
  );
  readonly _tag: Tag;
}

TaggedRequestClass interface

Added in v3.10.0 Source

Signature

interface TaggedRequestClass<
  Self,
  Tag extends string,
  Payload extends Struct.Fields,
  Success extends Schema.All,
  Failure extends Schema.All,
> extends Class<
  Self,
  Payload,
  Struct.Encoded<Payload>,
  Struct.Context<Payload>,
  Struct.Constructor<Omit<Payload, "_tag">>,
  TaggedRequest<
    Tag,
    Self,
    Struct.Encoded<Payload>,
    Struct.Context<Payload>,
    Schema.Type<Success>,
    Schema.Encoded<Success>,
    Schema.Type<Failure>,
    Schema.Encoded<Failure>,
    Schema.Context<Success> | Schema.Context<Failure>
  >,
  {}
> {
  constructor(
    props: RequiredKeys<Constructor<Omit<Payload, "_tag">>> extends never
      ? void | { [K in string | number | symbol]: Constructor<Omit<Payload, "_tag">>[K] }
      : { [K in string | number | symbol]: Constructor<Omit<Payload, "_tag">>[K] },
    options?: MakeOptions,
  );
  readonly _tag: Tag;
  readonly failure: Failure;
  readonly success: Success;
}

TaggedStruct type

Added in v3.10.0 Source

Signature

type TaggedStruct<Tag extends AST.LiteralValue, Fields extends Struct.Fields> = Struct<
  {
    _tag: tag<Tag>;
  } & Fields
>;

transform interface

Added in v3.10.0 Source

Signature

interface transform<From extends Schema.All, To extends Schema.All> extends transformOrFail<
  From,
  To
> {
  constructor(_: never);
  annotations(annotations: Schema<Type<To>>): transform<From, To>;
}

transformLiteral interface

Added in v3.10.0 Source

Signature

interface transformLiteral<
  Type extends AST.LiteralValue,
  Encoded extends AST.LiteralValue,
> extends transform<Literal<[Encoded]>, Literal<[Type]>> {
  constructor(_: never);
  annotations(annotations: Schema<Type>): transformLiteral<Type, Encoded>;
}

transformOrFail interface

Added in v3.10.0 Source

Signature

interface transformOrFail<
  From extends Schema.All,
  To extends Schema.All,
  R = never,
> extends AnnotableClass<
  transformOrFail<From, To, R>,
  Schema.Type<To>,
  Schema.Encoded<From>,
  Schema.Context<From> | Schema.Context<To> | R
> {
  constructor(_: never);
  readonly from: From;
  readonly to: To;
}

Tuple interface

Added in v3.10.0 Source

Signature

interface Tuple<Elements extends TupleType.Elements> extends TupleType<Elements, []> {
  constructor(_: never);
  annotations(annotations: Schema<ElementsType<Elements, readonly []>>): Tuple<Elements>;
}

Tuple2 interface

Added in v3.13.3 Source

Signature

interface Tuple2<Fst extends Schema.Any, Snd extends Schema.Any> extends AnnotableClass<
  Tuple2<Fst, Snd>,
  readonly [Schema.Type<Fst>, Schema.Type<Snd>],
  readonly [Schema.Encoded<Fst>, Schema.Encoded<Snd>],
  Schema.Context<Fst> | Schema.Context<Snd>
> {
  constructor(_: never);
  readonly elements: readonly [Fst, Snd];
  readonly rest: readonly [];
}

TupleType interface

Added in v3.10.0 Source

Signature

interface TupleType<
  Elements extends TupleType.Elements,
  Rest extends TupleType.Rest,
> extends AnnotableClass<
  TupleType<Elements, Rest>,
  TupleType.Type<Elements, Rest>,
  TupleType.Encoded<Elements, Rest>,
  Schema.Context<Elements[number]> | Schema.Context<Rest[number]>
> {
  constructor(_: never);
  readonly elements: Readonly<Elements>;
  readonly rest: Readonly<Rest>;
}

TypeLiteral interface

Added in v3.10.0 Source

Signature

interface TypeLiteral<
  Fields extends Struct.Fields,
  Records extends IndexSignature.Records,
> extends AnnotableClass<
  TypeLiteral<Fields, Records>,
  Simplify<TypeLiteral.Type<Fields, Records>>,
  Simplify<TypeLiteral.Encoded<Fields, Records>>,
  Struct.Context<Fields> | IndexSignature.Context<Records>
> {
  constructor(_: never);
  readonly fields: Readonly<Fields>;
  readonly records: Readonly<Records>;
  annotations(
    annotations: Schema<{ [K in string | number | symbol]: Type<Fields, Records>[K] }>,
  ): TypeLiteral<Fields, Records>;
  make(
    props: RequiredKeys<Constructor<Fields, Records>> extends never
      ? void | { [K in string | number | symbol]: Constructor<Fields, Records>[K] }
      : { [K in string | number | symbol]: Constructor<Fields, Records>[K] },
    options?: MakeOptions,
  ): { [K in string | number | symbol]: Type<Fields, Records>[K] };
}

UndefinedOr interface

Added in v3.10.0 Source

Signature

interface UndefinedOr<S extends Schema.All> extends Union<[S, typeof Undefined]> {
  constructor(_: never);
  annotations(annotations: Schema<Type<S> | undefined>): UndefinedOr<S>;
}

Union interface

Added in v3.10.0 Source

Signature

interface Union<Members extends ReadonlyArray<Schema.All>> extends AnnotableClass<
  Union<Members>,
  Schema.Type<Members[number]>,
  Schema.Encoded<Members[number]>,
  Schema.Context<Members[number]>
> {
  constructor(_: never);
  readonly members: Readonly<Members>;
}

API Interface

Element interface

Added in v3.10.0 Source

Signature

interface Element<S extends Schema.Any, Token extends Element.Token> extends Variance<
  Schema.Type<S>,
  Schema.Encoded<S>,
  Schema.Context<S>
> {
  readonly _Token: Token;
  readonly ast: OptionalType;
  readonly from: S;
  annotations(annotations: Annotations<Type<S>>): Element<S, Token>;
}

propertySignature interface

Added in v1.0.0 Source

Signature

interface propertySignature<S extends Schema.All> extends PropertySignature<
  ":",
  Schema.Type<S>,
  never,
  ":",
  Schema.Encoded<S>,
  false,
  Schema.Context<S>
> {
  readonly from: S;
  annotations(annotations: Annotations<Type<S>>): propertySignature<S>;
}

TemplateLiteral interface

Added in v3.10.0 Source

Signature

interface TemplateLiteral<A> extends SchemaClass<A> {
  constructor(_: never);
}

TemplateLiteralParser interface

Added in v3.10.0 Source

Signature

interface TemplateLiteralParser<
  Params extends array_.NonEmptyReadonlyArray<TemplateLiteralParserParameters>,
> extends Schema<
  GetTemplateLiteralParserType<Params>,
  GetTemplateLiteralParserEncoded<Params>,
  Schema.Context<Params[number]>
> {
  readonly params: Params;
}

ArrayFormatter

Signature

declare class ArrayFormatterIssue extends Variance<{
  readonly _tag: "Composite" | "Pointer" | "Unexpected" | "Missing" | "Refinement" | "Transformation" | "Type" | "Forbidden";
  readonly message: string;
  readonly path: readonly Array<string | number | symbol>;
}, {
  _tag: "Composite" | "Pointer" | "Unexpected" | "Missing" | "Refinement" | "Transformation" | "Type" | "Forbidden";
  message: string;
  path: readonly Array<string | number | {
    _tag: "symbol";
    key: string;
  }>;
}, never, this> {
  constructor(_: never);
}

BigDecimal Constructors

Signature

declare class BigDecimalFromSelf extends Variance<BigDecimal, BigDecimal, never, this> {
  constructor(_: never);
}

Signature

declare const NegativeBigDecimalFromSelf: filter<Schema<bigDecimal_.BigDecimal>>;

Signature

declare const NonNegativeBigDecimalFromSelf: filter<Schema<bigDecimal_.BigDecimal>>;

Signature

declare const NonPositiveBigDecimalFromSelf: filter<Schema<bigDecimal_.BigDecimal>>;

Signature

declare const PositiveBigDecimalFromSelf: filter<Schema<bigDecimal_.BigDecimal>>;

BigDecimal Filters

Signature

declare function betweenBigDecimal<S extends Any>(
  minimum: BigDecimal,
  maximum: BigDecimal,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends BigDecimal>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

Signature

declare function greaterThanBigDecimal<S extends Any>(
  min: BigDecimal,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends BigDecimal>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

Signature

declare function greaterThanOrEqualToBigDecimal<S extends Any>(
  min: BigDecimal,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends BigDecimal>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

Signature

declare function lessThanBigDecimal<S extends Any>(
  max: BigDecimal,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends BigDecimal>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

Signature

declare function lessThanOrEqualToBigDecimal<S extends Any>(
  max: BigDecimal,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends BigDecimal>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

Signature

declare function negativeBigDecimal<S extends Any>(
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends BigDecimal>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

Signature

declare function nonNegativeBigDecimal<S extends Any>(
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends BigDecimal>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

Signature

declare function nonPositiveBigDecimal<S extends Any>(
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends BigDecimal>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

Signature

declare function positiveBigDecimal<S extends Any>(
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends BigDecimal>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

BigDecimal Transformations

BigDecimal

Added in v3.10.0 Source

Signature

declare class BigDecimal extends Variance<BigDecimal, string, never, this> {
  constructor(_: never);
}

A schema that transforms a number into a BigDecimal. When encoding, this Schema will produce incorrect results if the BigDecimal exceeds the 64-bit range of a number.

Signature

declare class BigDecimalFromNumber extends Variance<BigDecimal, number, never, this> {
  constructor(_: never);
}

Clamps a BigDecimal between a minimum and a maximum value.

Signature

declare function clampBigDecimal(
  minimum: BigDecimal,
  maximum: BigDecimal,
): <S extends Any, A extends BigDecimal>(
  self: S & Schema<A, Encoded<S>, Context<S>>,
) => transform<S, filter<SchemaClass<A, A, never>>>;

Bigint Constructors

NegativeBigInt

Added in v3.10.0 Source

Signature

declare const NegativeBigInt: filter<Schema<bigint, string>>;

Signature

declare const NegativeBigIntFromSelf: filter<Schema<bigint>>;

Signature

declare const NonNegativeBigInt: filter<Schema<bigint, string>>;

Signature

declare const NonNegativeBigIntFromSelf: filter<Schema<bigint>>;

Signature

declare const NonPositiveBigInt: filter<Schema<bigint, string>>;

Signature

declare const NonPositiveBigIntFromSelf: filter<Schema<bigint>>;

PositiveBigInt

Added in v3.10.0 Source

Signature

declare const PositiveBigInt: filter<Schema<bigint, string>>;

Signature

declare const PositiveBigIntFromSelf: filter<Schema<bigint>>;

Bigint Filters

betweenBigInt

Added in v3.10.0 Source

Signature

declare function betweenBigInt<S extends Any>(
  min: bigint,
  max: bigint,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends bigint>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

Signature

declare function greaterThanBigInt<S extends Any>(
  min: bigint,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends bigint>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

Signature

declare function greaterThanOrEqualToBigInt<S extends Any>(
  min: bigint,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends bigint>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

lessThanBigInt

Added in v3.10.0 Source

Signature

declare function lessThanBigInt<S extends Any>(
  max: bigint,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends bigint>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

Signature

declare function lessThanOrEqualToBigInt<S extends Any>(
  max: bigint,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends bigint>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

negativeBigInt

Added in v3.10.0 Source

Signature

declare function negativeBigInt<S extends Any>(
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends bigint>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

Signature

declare function nonNegativeBigInt<S extends Any>(
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends bigint>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

Signature

declare function nonPositiveBigInt<S extends Any>(
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends bigint>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

positiveBigInt

Added in v3.10.0 Source

Signature

declare function positiveBigInt<S extends Any>(
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends bigint>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

Bigint Transformations

This schema transforms a number into a bigint by parsing the number using the BigInt function.

It returns an error if the value can't be safely encoded as a number due to being out of range.

Signature

declare class BigIntFromNumber extends Variance<bigint, number, never, this> {
  constructor(_: never);
}

clampBigInt

Added in v3.10.0 Source

Clamps a bigint between a minimum and a maximum value.

Signature

declare function clampBigInt(
  minimum: bigint,
  maximum: bigint,
): <S extends Any, A extends bigint>(
  self: S & Schema<A, Encoded<S>, Context<S>>,
) => transform<S, filter<SchemaClass<A, A, never>>>;

Boolean Constructors

Converts an arbitrary value to a boolean by testing whether it is truthy. Uses !!val to coerce the value to a boolean.

See

  • https://developer.mozilla.org/docs/Glossary/Truthy

Signature

declare class BooleanFromUnknown extends Variance<boolean, unknown, never, this> {
  constructor(_: never);
}

Boolean Transformations

Converts an string value into its corresponding boolean ("true" as true and "false" as false).

Signature

declare class BooleanFromString extends Variance<boolean, "true" | "false", never, this> {
  constructor(_: never);
}

Not

Added in v3.10.0 Source

Signature

declare class Not extends Variance<boolean, boolean, never, this> {
  constructor(_: never);
}

Branding

brand

Added in v3.10.0 Source

Returns a nominal branded schema by applying a brand to a given schema.

Signature

declare const brand: <S extends Any, B extends string | symbol>(
  brand: B,
  annotations?: Schema<Type<S> & Brand<B>, readonly []>,
) => (self: S) => brand<S, B>;

Example

Schema<A> + B -> Schema<A & Brand<B>>

Example

import * as Schema from "effect/Schema"

const Int = Schema.Number.pipe(Schema.int(), Schema.brand("Int"))
type Int = Schema.Schema.Type<typeof Int> // number & Brand<"Int">

BrandSchema interface

Added in v3.10.0 Source

Signature

interface BrandSchema<A extends Brand<any>, I = A, R = never> extends AnnotableClass<
  BrandSchema<A, I, R>,
  A,
  I,
  R
> {
  constructor(_: never);
  make(a: Unbranded<A>, options?: MakeOptions): A;
}

Cause Transformations

Cause

Added in v3.10.0 Source

Signature

declare const Cause: <E extends All, D extends All>(__namedParameters: {
  readonly defect: D;
  readonly error: E;
}) => Cause<E, D>;

CauseFromSelf

Added in v3.10.0 Source

Signature

declare const CauseFromSelf: <E extends All, D extends All>(__namedParameters: {
  readonly defect: D;
  readonly error: E;
}) => CauseFromSelf<E, D>;

Cause Utils

CauseEncoded type

Added in v3.10.0 Source

Signature

type CauseEncoded<E, D> =
  | {
      readonly _tag: "Empty";
    }
  | {
      readonly _tag: "Fail";
      readonly error: E;
    }
  | {
      readonly _tag: "Die";
      readonly defect: D;
    }
  | {
      readonly _tag: "Interrupt";
      readonly fiberId: FiberIdEncoded;
    }
  | {
      readonly _tag: "Sequential";
      readonly left: CauseEncoded<E, D>;
      readonly right: CauseEncoded<E, D>;
    }
  | {
      readonly _tag: "Parallel";
      readonly left: CauseEncoded<E, D>;
      readonly right: CauseEncoded<E, D>;
    };

Chunk

ChunkFromSelf

Added in v3.10.0 Source

Signature

declare const ChunkFromSelf: <Value extends Any>(value: Value) => ChunkFromSelf<Value>;

Signature

declare const NonEmptyChunkFromSelf: <Value extends Any>(
  value: Value,
) => NonEmptyChunkFromSelf<Value>;

Chunk Transformations

Chunk

Added in v3.10.0 Source

Signature

declare function Chunk<Value extends Any>(value: Value): Chunk<Value>;

NonEmptyChunk

Added in v3.10.0 Source

Signature

declare function NonEmptyChunk<Value extends Any>(value: Value): NonEmptyChunk<Value>;

Classes

Class

Added in v3.10.0 Source

Signature

declare const Class: <Self = never>(
  identifier: string,
) => <Fields extends Fields>(
  fieldsOr: Fields | HasFields<Fields>,
  annotations?: ClassAnnotations<Self, { [K in string | number | symbol]: Type<Fields>[K] }>,
) => [Self] extends [never]
  ? "Missing `Self` generic - use `class Self extends Class<Self>()({ ... })`"
  : Class<
      Self,
      Fields,
      Encoded<Fields>,
      Context<Fields[keyof Fields]>,
      Constructor<Fields>,
      {},
      {}
    >;

Example

import { Schema } from "effect"

class MyClass extends Schema.Class<MyClass>("MyClass")({
  someField: Schema.String,
}) {
  someMethod() {
    return this.someField + "bar"
  }
}

TaggedClass

Added in v3.10.0 Source

Signature

declare const TaggedClass: <Self = never>(
  identifier?: string,
) => <Tag extends string, Fields extends Fields>(
  tag: Tag,
  fieldsOr: Fields | HasFields<Fields>,
  annotations?: ClassAnnotations<
    Self,
    {
      [K in string | number | symbol]: Type<
        {
          readonly _tag: tag<Tag>;
        } & Fields
      >[K];
    }
  >,
) => [Self] extends [never]
  ? 'Missing `Self` generic - use `class Self extends TaggedClass<Self>()("Tag", { ... })`'
  : TaggedClass<
      Self,
      Tag,
      {
        readonly _tag: tag<Tag>;
      } & Fields
    >;

Example

import { Schema } from "effect"

class MyClass extends Schema.TaggedClass<MyClass>("MyClass")("MyClass", {
  a: Schema.String,
}) {}

TaggedError

Added in v3.10.0 Source

Signature

declare function TaggedError<Self = never>(
  identifier?: string,
): <Tag extends string, Fields extends Fields>(
  tag: Tag,
  fieldsOr: Fields | HasFields<Fields>,
  annotations?: ClassAnnotations<
    Self,
    {
      [K in string | number | symbol]: Type<
        {
          readonly _tag: tag<Tag>;
        } & Fields
      >[K];
    }
  >,
) => [Self] extends [never]
  ? 'Missing `Self` generic - use `class Self extends TaggedError<Self>()("Tag", { ... })`'
  : TaggedErrorClass<
      Self,
      Tag,
      {
        readonly _tag: tag<Tag>;
      } & Fields
    >;

TaggedRequest

Added in v3.10.0 Source

Signature

declare const TaggedRequest: <Self = never>(
  identifier?: string,
) => <Tag extends string, Payload extends Fields, Success extends All, Failure extends All>(
  tag: Tag,
  options: {
    failure: Failure;
    payload: Payload;
    success: Success;
  },
  annotations?: ClassAnnotations<
    Self,
    {
      [K in string | number | symbol]: Type<
        {
          readonly _tag: tag<Tag>;
        } & Payload
      >[K];
    }
  >,
) => [Self] extends [never]
  ? 'Missing `Self` generic - use `class Self extends TaggedRequest<Self>()("Tag", SuccessSchema, FailureSchema, { ... })`'
  : TaggedRequestClass<
      Self,
      Tag,
      {
        readonly _tag: tag<Tag>;
      } & Payload,
      Success,
      Failure
    >;

Example

import { Schema } from "effect"

class MyRequest extends Schema.TaggedRequest<MyRequest>("MyRequest")("MyRequest", {
  failure: Schema.String,
  success: Schema.Number,
  payload: { id: Schema.String },
}) {}

Combinators

Attaches a property signature with the specified key and value to the schema. This API is useful when you want to add a property to your schema which doesn't describe the shape of the input, but rather maps to another schema, for example when you want to add a discriminant to a simple union.

Signature

declare const attachPropertySignature: {
  <K extends PropertyKey, V extends symbol | LiteralValue, A>(
    key: K,
    value: V,
    annotations?: Schema<A & { [k in PropertyKey]: V }, readonly []>,
  ): <I, R>(schema: Schema<A, I, R>) => SchemaClass<A & { [k in PropertyKey]: V }, I, R>;
  <A, I, R, K extends PropertyKey, V extends symbol | LiteralValue>(
    schema: Schema<A, I, R>,
    key: K,
    value: V,
    annotations?: Schema<A & { [k in PropertyKey]: V }, readonly []>,
  ): SchemaClass<A & { [k in PropertyKey]: V }, I, R>;
};

Example

import * as assert from "node:assert"
import * as S from "effect/Schema"
import { pipe } from "effect/Function"

const Circle = S.Struct({ radius: S.Number })
const Square = S.Struct({ sideLength: S.Number })
const Shape = S.Union(
  Circle.pipe(S.attachPropertySignature("kind", "circle")),
  Square.pipe(S.attachPropertySignature("kind", "square")),
)

assert.deepStrictEqual(S.decodeSync(Shape)({ radius: 10 }), {
  kind: "circle",
  radius: 10,
})

compose

Added in v3.10.0 Source

Signature

declare const compose: {
  <To extends Any, From extends Any, C extends any>(
    to: To & Schema<Type<To>, C, Context<To>>,
  ): (from: From) => transform<From, To>;
  <To extends Any>(
    to: To,
  ): <From extends Any, B extends any>(
    from: From & Schema<B, Encoded<From>, Context<From>>,
  ) => transform<From, To>;
  <To extends Any>(
    to: To,
    options?: {
      readonly strict: true;
    },
  ): <From extends Any>(
    from: From & Schema<Encoded<To>, Encoded<From>, Context<From>>,
  ) => transform<From, To>;
  <To extends Any>(
    to: To,
    options: {
      readonly strict: false;
    },
  ): <From extends Any>(from: From) => transform<From, To>;
  <From extends Any, To extends Any, C extends any>(
    from: From,
    to: To & Schema<Type<To>, C, Context<To>>,
  ): transform<From, To>;
  <From extends Any, B extends any, To extends Any>(
    from: From & Schema<B, Encoded<From>, Context<From>>,
    to: To,
  ): transform<From, To>;
  <From extends Any, To extends Any>(
    from: From & Schema<Encoded<To>, Encoded<From>, Context<From>>,
    to: To,
    options?: {
      readonly strict: true;
    },
  ): transform<From, To>;
  <From extends Any, To extends Any>(
    from: From,
    to: To,
    options: {
      readonly strict: false;
    },
  ): transform<From, To>;
};

extend

Added in v3.10.0 Source

Extends a schema with another schema.

Not all extensions are supported, and their support depends on the nature of the involved schemas.

Possible extensions include: - Schema.String with another Schema.String refinement or a string literal - Schema.Number with another Schema.Number refinement or a number literal - Schema.Boolean with another Schema.Boolean refinement or a boolean literal - A struct with another struct where overlapping fields support extension - A struct with in index signature - A struct with a union of supported schemas - A refinement of a struct with a supported schema - A suspend of a struct with a supported schema - A transformation between structs where the โ€œfromโ€ and โ€œtoโ€ sides have no overlapping fields with the target struct

Signature

declare const extend: {
  <That extends Any>(that: That): <Self extends Any>(self: Self) => extend<Self, That>;
  <Self extends Any, That extends Any>(self: Self, that: That): extend<Self, That>;
};

Example

import * as Schema from "effect/Schema"

const schema = Schema.Struct({
  a: Schema.String,
  b: Schema.String,
})

// const extended: Schema<
//   {
//     readonly a: string
//     readonly b: string
//   } & {
//     readonly c: string
//   } & {
//     readonly [x: string]: string
//   }
// >
const extended = Schema.asSchema(
  schema.pipe(
    Schema.extend(Schema.Struct({ c: Schema.String })), // <= you can add more fields
    Schema.extend(Schema.Record({ key: Schema.String, value: Schema.String })), // <= you can add index signatures
  ),
)

keyof

Added in v3.10.0 Source

Signature

declare function keyof<A, I, R>(self: Schema<A, I, R>): SchemaClass<keyof A>;

mutable

Added in v3.10.0 Source

Creates a new schema with shallow mutability applied to its properties.

Signature

declare const mutable: <S extends Any>(schema: S) => mutable<S>;

NullishOr

Added in v3.10.0 Source

Signature

declare const NullishOr: <S extends All>(self: S) => NullishOr<S>;

NullOr

Added in v3.10.0 Source

Signature

declare const NullOr: <S extends All>(self: S) => NullOr<S>;

partial

Added in v3.10.0 Source

Signature

declare function partial<A, I, R>(
  self: Schema<A, I, R>,
): SchemaClass<
  { [K in string | number | symbol]: A[K] },
  { [K in string | number | symbol]: I[K] },
  R
>;

partialWith

Added in v3.10.0 Source

Signature

declare const partialWith: {
  <
    Options extends {
      readonly exact: true;
    },
  >(
    options: Options,
  ): <A, I, R>(
    self: Schema<A, I, R>,
  ) => SchemaClass<
    { [K in string | number | symbol]: A[K] },
    { [K in string | number | symbol]: I[K] },
    R
  >;
  <
    A,
    I,
    R,
    Options extends
      | {
          readonly exact: true;
        }
      | undefined,
  >(
    self: Schema<A, I, R>,
    options: Options,
  ): SchemaClass<
    { [K in string | number | symbol]: A[K] },
    { [K in string | number | symbol]: I[K] },
    R
  >;
};

required

Added in v3.10.0 Source

Signature

declare function required<A, I, R>(
  self: Schema<A, I, R>,
): SchemaClass<
  { [K in string | number | symbol]: A[K] },
  { [K in string | number | symbol]: I[K] },
  R
>;

UndefinedOr

Added in v3.10.0 Source

Signature

declare const UndefinedOr: <S extends All>(self: S) => UndefinedOr<S>;

Union

Added in v3.10.0 Source

Signature

declare function Union<Members extends readonly [All, All, All]>(...members: Members): Union<Members>
declare function Union<Member extends All>(member: Member): Member
declare function Union(): typeof Never
declare function Union<Members extends readonly Array<All>>(...members: Members): Schema<Type<Members[number]>, Encoded<Members[number]>, Context<Members[number]>>

Config Validations

Config

Added in v3.10.0 Source

Signature

declare function Config<A, I extends string>(name: string, schema: Schema<A, I>): Config<A>;

Constructor Utils

MakeOptions type

Added in v3.13.4 Source

Signature

type MakeOptions =
  | boolean
  | {
      readonly disableValidation?: boolean;
    };

Constructors

ArrayEnsure

Added in v3.10.0 Source

Signature

declare function ArrayEnsure<Value extends Any>(value: Value): ArrayEnsure<Value>;

declare

Added in v3.10.0 Source

The constraint R extends Schema.Context<P[number]> enforces dependencies solely from typeParameters. This ensures that when you call Schema.to or Schema.from, you receive a schema with a never context.

Signature

declare const declare: {
  <A>(is: (input: unknown) => input is A, annotations?: Schema<A, readonly []>): declare<A>;
  <A, I, P extends readonly Array<All>>(typeParameters: P, options: {
    readonly decode: (...typeParameters: { [K in string | number | symbol]: Schema<Type<P[K]>, Encoded<P[K]>, never> }) => (input: unknown, options: ParseOptions, ast: Declaration) => Effect<A, ParseIssue, never>;
    readonly encode: (...typeParameters: { [K in string | number | symbol]: Schema<Type<P[K]>, Encoded<P[K]>, never> }) => (input: unknown, options: ParseOptions, ast: Declaration) => Effect<I, ParseIssue, never>;
  }, annotations?: Schema<A, { [K in string | number | symbol]: Type<P[K]> }>): declare<A, I, P>;
}

Enums

Added in v3.10.0 Source

Signature

declare const Enums: <A extends EnumsDefinition>(enums: A) => Enums<A>;

fromBrand

Added in v3.10.0 Source

Signature

declare function fromBrand<C extends Brand<string | symbol>, A extends Brand<string | symbol>>(
  constructor: Constructor<C>,
  annotations?: Filter<C, A>,
): <I, R>(self: Schema<A, I, R>) => BrandSchema<A & C, I, R>;

instanceOf

Added in v3.10.0 Source

Signature

declare const instanceOf: <A extends (...args: any) => any>(
  constructor: A,
  annotations?: Schema<InstanceType<A>, readonly []>,
) => instanceOf<InstanceType<A>>;

Literal

Added in v3.10.0 Source

Signature

declare function Literal<Literals extends readonly [LiteralValue, LiteralValue]>(...literals: Literals): Literal<Literals>
declare function Literal(): Never
declare function Literal<Literals extends readonly Array<LiteralValue>>(...literals: Literals): SchemaClass<Literals[number]>

make

Added in v3.10.0 Source

Signature

declare function make<A, I = A, R = never>(ast: AST): SchemaClass<A, I, R>;

NonEmptyArray

Added in v3.10.0 Source

Signature

declare const NonEmptyArray: <Value extends Any>(value: Value) => NonEmptyArray<Value>;

Signature

declare function NonEmptyArrayEnsure<Value extends Any>(value: Value): NonEmptyArrayEnsure<Value>;

pickLiteral

Added in v3.10.0 Source

Creates a new Schema from a literal schema.

Signature

declare function pickLiteral<A extends LiteralValue, L extends readonly [A, A]>(
  ...literals: L
): <I, R>(_schema: Schema<A, I, R>) => Literal<[...Array<L>]>;

Record

Added in v3.10.0 Source

Signature

declare function Record<K extends All, V extends All>(options: {
  readonly key: K;
  readonly value: V;
}): Record$<K, V>;

Struct

Added in v3.10.0 Source

Signature

declare function Struct<Fields extends Fields, Records extends readonly [Record, Record]>(
  fields: Fields,
  ...records: Records
): TypeLiteral<Fields, Records>;
declare function Struct<Fields extends Fields>(fields: Fields): Struct<Fields>;

suspend

Added in v3.10.0 Source

Signature

declare const suspend: <A, I, R>(f: () => Schema<A, I, R>) => suspend<A, I, R>;

TaggedStruct

Added in v3.10.0 Source

A tagged struct is a struct that has a tag property that is used to distinguish between different types of objects.

The tag is optional when using the make method.

Signature

declare const TaggedStruct: <Tag extends LiteralValue, Fields extends Fields>(
  value: Tag,
  fields: Fields,
) => TaggedStruct<Tag, Fields>;

Example

import * as assert from "node:assert"
import { Schema } from "effect"

const User = Schema.TaggedStruct("User", {
  name: Schema.String,
  age: Schema.Number,
})

assert.deepStrictEqual(User.make({ name: "John", age: 44 }), {
  _tag: "User",
  name: "John",
  age: 44,
})

Creates a new Schema which transforms literal values.

Signature

declare function transformLiteral<Encoded extends LiteralValue, Type extends LiteralValue>(
  from: Encoded,
  to: Type,
): transformLiteral<Type, Encoded>;

Creates a new Schema which maps between corresponding literal values.

Signature

declare function transformLiterals<A extends readonly [readonly [LiteralValue, LiteralValue], readonly [LiteralValue, LiteralValue], readonly [LiteralValue, LiteralValue]]>(...pairs: A): Union<{ [I in string | number | symbol]: transformLiteral<A[I][1], A[I][0]> }>
declare function transformLiterals<Encoded extends LiteralValue, Type extends LiteralValue>(pairs: [Encoded, Type]): transformLiteral<Type, Encoded>
declare function transformLiterals<A extends readonly Array<readonly [LiteralValue, LiteralValue]>>(...pairs: A): Schema<A[number][1], A[number][0]>

Tuple

Added in v3.10.0 Source

Signature

declare function Tuple<
  Elements extends Elements,
  Rest extends readonly [Any | Element<Any, "">, Any | Element<Any, "">],
>(elements: Elements, ...rest: Rest): TupleType<Elements, Rest>;
declare function Tuple<Fst extends Any, Snd extends Any>(fst: Fst, snd: Snd): Tuple2<Fst, Snd>;
declare function Tuple<Elements extends Elements>(...elements: Elements): Tuple<Elements>;

Signature

declare function UniqueSymbolFromSelf<S extends symbol>(symbol: S): SchemaClass<S>;

Data Transformations

Data

Added in v3.10.0 Source

Type and Encoded must extend Readonly<Record<string, any>> | ReadonlyArray<any> to be compatible with this API.

Signature

declare const Data: <S extends Any, A extends readonly Array<unknown> | Readonly<Record<string, unknown>>, I extends readonly Array<unknown> | Readonly<Record<string, unknown>>>(value: S & Schema<A & Type<S>, I & Encoded<S>, Context<S>>) => Data<S>

DataFromSelf

Added in v3.10.0 Source

Type and Encoded must extend Readonly<Record<string, any>> | ReadonlyArray<any> to be compatible with this API.

Signature

declare const DataFromSelf: <S extends Any, A extends readonly Array<unknown> | Readonly<Record<string, unknown>>, I extends readonly Array<unknown> | Readonly<Record<string, unknown>>>(value: S & Schema<A & Type<S>, I & Encoded<S>, Context<S>>) => DataFromSelf<S>

Date Constructors

DateFromSelf

Added in v3.10.0 Source

Describes a schema that accommodates potentially invalid Date instances, such as new Date("Invalid Date"), without rejection.

Signature

declare class DateFromSelf extends Variance<Date, Date, never, this> {
  constructor(_: never);
}

Defines a schema that ensures only valid dates are accepted. This schema rejects values like new Date("Invalid Date"), which, despite being a Date instance, represents an invalid date. Such stringent validation ensures that all date objects processed through this schema are properly formed and represent real dates.

Signature

declare class ValidDateFromSelf extends Variance<Date, Date, never, this> {
  constructor(_: never);
}

Date Filters

betweenDate

Added in v3.10.0 Source

Signature

declare function betweenDate<S extends Any>(
  min: Date,
  max: Date,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends Date>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

Signature

declare function greaterThanDate<S extends Any>(
  min: Date,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends Date>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

Signature

declare function greaterThanOrEqualToDate<S extends Any>(
  min: Date,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends Date>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

lessThanDate

Added in v3.10.0 Source

Signature

declare function lessThanDate<S extends Any>(
  max: Date,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends Date>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

Signature

declare function lessThanOrEqualToDate<S extends Any>(
  max: Date,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends Date>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

validDate

Added in v3.10.0 Source

Defines a filter that specifically rejects invalid dates, such as new Date("Invalid Date"). This filter ensures that only properly formatted and valid date objects are accepted, enhancing data integrity by preventing erroneous date values from being processed.

Signature

declare function validDate<S extends Any>(
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends Date>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

Date Transformations

DateFromNumber

Added in v3.10.0 Source

Defines a schema that converts a number into a Date object using the new Date constructor. This schema does not validate the numerical input, allowing potentially invalid values such as NaN, Infinity, and -Infinity to be converted into Date objects. During the encoding process, any invalid Date object will be encoded to NaN.

Signature

declare class DateFromNumber extends Variance<Date, number, never, this> {
  constructor(_: never);
}

DateFromString

Added in v3.10.0 Source

Defines a schema that attempts to convert a string to a Date object using the new Date constructor. This conversion is lenient, meaning it does not reject strings that do not form valid dates (e.g., using new Date("Invalid Date") results in a Date object, despite being invalid).

Signature

declare class DateFromString extends Variance<Date, string, never, this> {
  constructor(_: never);
}

DateTime.Utc Constructors

Describes a schema that represents a DateTime.Utc instance.

Signature

declare class DateTimeUtcFromSelf extends Variance<Utc, Utc, never, this> {
  constructor(_: never);
}

DateTime.Utc Transformations

DateTimeUtc

Added in v3.10.0 Source

Defines a schema that attempts to convert a string to a DateTime.Utc instance using the DateTime.unsafeMake constructor.

Signature

declare class DateTimeUtc extends Variance<Utc, string, never, this> {
  constructor(_: never);
}

Defines a schema that attempts to convert a Date to a DateTime.Utc instance using the DateTime.unsafeMake constructor.

Signature

declare class DateTimeUtcFromDate extends Variance<Utc, Date, never, this> {
  constructor(_: never);
}

Defines a schema that attempts to convert a number to a DateTime.Utc instance using the DateTime.unsafeMake constructor.

Signature

declare class DateTimeUtcFromNumber extends Variance<Utc, number, never, this> {
  constructor(_: never);
}

DateTime.Zoned Constructors

Describes a schema that represents a DateTime.Zoned instance.

Signature

declare class DateTimeZonedFromSelf extends Variance<Zoned, Zoned, never, this> {
  constructor(_: never);
}

DateTime.Zoned Transformations

DateTimeZoned

Added in v3.10.0 Source

Defines a schema that attempts to convert a string to a DateTime.Zoned instance.

Signature

declare class DateTimeZoned extends Variance<Zoned, string, never, this> {
  constructor(_: never);
}

Decoding

decode

Added in v3.10.0 Source

Signature

declare const decode: <A, I, R>(
  schema: Schema<A, I, R>,
  options?: ParseOptions,
) => (i: I, overrideOptions?: ParseOptions) => Effect.Effect<A, ParseResult.ParseError, R>;

decodeEither

Added in v3.10.0 Source

Signature

declare const decodeEither: <A, I>(
  schema: Schema<A, I, never>,
  options?: ParseOptions,
) => (i: I, overrideOptions?: ParseOptions) => either_.Either<A, ParseResult.ParseError>;

decodeOption

Added in v3.10.0 Source

Signature

declare const decodeOption: <A, I>(
  schema: Schema.Schema<A, I, never>,
  options?: AST.ParseOptions,
) => (i: I, overrideOptions?: AST.ParseOptions) => Option.Option<A>;

decodePromise

Added in v3.10.0 Source

Signature

declare const decodePromise: <A, I>(
  schema: Schema<A, I, never>,
  options?: ParseOptions,
) => (i: I, overrideOptions?: ParseOptions) => Promise<A>;

decodeSync

Added in v3.10.0 Source

Signature

declare const decodeSync: <A, I>(
  schema: Schema.Schema<A, I, never>,
  options?: AST.ParseOptions,
) => (i: I, overrideOptions?: AST.ParseOptions) => A;

decodeUnknown

Added in v3.10.0 Source

Signature

declare function decodeUnknown<A, I, R>(
  schema: Schema<A, I, R>,
  options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => Effect<A, ParseError, R>;

Signature

declare function decodeUnknownEither<A, I>(
  schema: Schema<A, I, never>,
  options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => Either<A, ParseError>;

Signature

declare function decodeUnknownOption<A, I>(
  schema: Schema<A, I, never>,
  options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => Option<A>;

Signature

declare function decodeUnknownPromise<A, I>(
  schema: Schema<A, I, never>,
  options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => Promise<A>;

Signature

declare function decodeUnknownSync<A, I>(
  schema: Schema<A, I, never>,
  options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => A;

deserialize

Added in v3.10.0 Source

Signature

declare const deserialize: {
  (value: unknown): <A, I, R>(self: Serializable<A, I, R>) => Effect<A, ParseError, R>;
  <A, I, R>(self: Serializable<A, I, R>, value: unknown): Effect<A, ParseError, R>;
};

Signature

declare const deserializeExit: {
  (
    value: unknown,
  ): <SA, SI, FA, FI, R>(
    self: WithResult<SA, SI, FA, FI, R>,
  ) => Effect<Exit<SA, FA>, ParseError, R>;
  <SA, SI, FA, FI, R>(
    self: WithResult<SA, SI, FA, FI, R>,
    value: unknown,
  ): Effect<Exit<SA, FA>, ParseError, R>;
};

Signature

declare const deserializeFailure: {
  (
    value: unknown,
  ): <SA, SI, FA, FI, R>(self: WithResult<SA, SI, FA, FI, R>) => Effect<FA, ParseError, R>;
  <SA, SI, FA, FI, R>(
    self: WithResult<SA, SI, FA, FI, R>,
    value: unknown,
  ): Effect<FA, ParseError, R>;
};

Signature

declare const deserializeSuccess: {
  (
    value: unknown,
  ): <SA, SI, FA, FI, R>(self: WithResult<SA, SI, FA, FI, R>) => Effect<SA, ParseError, R>;
  <SA, SI, FA, FI, R>(
    self: WithResult<SA, SI, FA, FI, R>,
    value: unknown,
  ): Effect<SA, ParseError, R>;
};

Defect

Defect

Added in v3.10.0 Source

Defines a schema for handling JavaScript errors (Error instances) and other types of defects. It decodes objects into Error instances if they match the expected structure (i.e., have a message and optionally a name and stack), or converts other values to their string representations.

When encoding, it converts Error instances back into plain objects containing only the error's name and message, or other values into their string forms.

This is useful for serializing and deserializing errors across network boundaries where error objects do not natively serialize.

Signature

declare class Defect extends Variance<unknown, unknown, never, this> {
  constructor(_: never);
}

Duration Constructors

Signature

declare class DurationFromSelf extends Variance<Duration, Duration, never, this> {
  constructor(_: never);
}

Duration Filters

Signature

declare function betweenDuration<S extends Any>(
  minimum: DurationInput,
  maximum: DurationInput,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends Duration>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

Signature

declare function greaterThanDuration<S extends Any>(
  min: DurationInput,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends Duration>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

Signature

declare function greaterThanOrEqualToDuration<S extends Any>(
  min: DurationInput,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends Duration>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

Signature

declare function lessThanDuration<S extends Any>(
  max: DurationInput,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends Duration>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

Signature

declare function lessThanOrEqualToDuration<S extends Any>(
  max: DurationInput,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends Duration>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

Duration Transformations

clampDuration

Added in v3.10.0 Source

Clamps a Duration between a minimum and a maximum value.

Signature

declare function clampDuration(
  minimum: DurationInput,
  maximum: DurationInput,
): <S extends Any, A extends Duration>(
  self: S & Schema<A, Encoded<S>, Context<S>>,
) => transform<S, filter<SchemaClass<A, A, never>>>;

Duration

Added in v3.10.0 Source

A schema that converts a JSON-compatible tagged union into a Duration.

Signature

declare class Duration extends Variance<
  Duration,
  DurationEncoded | readonly [number, number],
  never,
  this
> {
  constructor(_: never);
}

A schema that transforms a (possibly Infinite) non negative number into a Duration. Treats the value as the number of milliseconds.

Signature

declare class DurationFromMillis extends Variance<Duration, number, never, this> {
  constructor(_: never);
}

A schema that transforms a non negative bigint into a Duration. Treats the value as the number of nanoseconds.

Signature

declare class DurationFromNanos extends Variance<Duration, bigint, never, this> {
  constructor(_: never);
}

Duration Utils

DurationEncoded type

Added in v3.12.8 Source

Signature

type DurationEncoded =
  | {
      readonly _tag: "Millis";
      readonly millis: number;
    }
  | {
      readonly _tag: "Nanos";
      readonly nanos: string;
    }
  | {
      readonly _tag: "Infinity";
    };

Either Transformations

Either

Added in v3.10.0 Source

Signature

declare const Either: <R extends All, L extends All>(__namedParameters: {
  readonly left: L;
  readonly right: R;
}) => Either<R, L>;

EitherFromSelf

Added in v3.10.0 Source

Signature

declare const EitherFromSelf: <R extends All, L extends All>(__namedParameters: {
  readonly left: L;
  readonly right: R;
}) => EitherFromSelf<R, L>;

Signature

declare const EitherFromUnion: <Right extends All, Left extends All>(__namedParameters: {
  readonly left: Left;
  readonly right: Right;
}) => EitherFromUnion<Right, Left>;

Example

import * as Schema from "effect/Schema"

// Schema<string | number, Either<string, number>>
Schema.EitherFromUnion({ left: Schema.String, right: Schema.Number })

Either Utils

EitherEncoded type

Added in v3.10.0 Source

Signature

type EitherEncoded<IR, IL> = RightEncoded<IR> | LeftEncoded<IL>;

LeftEncoded type

Added in v3.10.0 Source

Signature

type LeftEncoded<IE> = {
  readonly _tag: "Left";
  readonly left: IE;
};

RightEncoded type

Added in v3.10.0 Source

Signature

type RightEncoded<IA> = {
  readonly _tag: "Right";
  readonly right: IA;
};

Encoding

encode

Added in v3.10.0 Source

Signature

declare const encode: <A, I, R>(
  schema: Schema<A, I, R>,
  options?: ParseOptions,
) => (a: A, overrideOptions?: ParseOptions) => Effect.Effect<I, ParseResult.ParseError, R>;

encodeEither

Added in v3.10.0 Source

Signature

declare const encodeEither: <A, I>(
  schema: Schema<A, I, never>,
  options?: ParseOptions,
) => (a: A, overrideOptions?: ParseOptions) => either_.Either<I, ParseResult.ParseError>;

encodeOption

Added in v3.10.0 Source

Signature

declare const encodeOption: <A, I>(
  schema: Schema.Schema<A, I, never>,
  options?: AST.ParseOptions,
) => (input: A, overrideOptions?: AST.ParseOptions) => Option.Option<I>;

encodePromise

Added in v3.10.0 Source

Signature

declare const encodePromise: <A, I>(
  schema: Schema<A, I, never>,
  options?: ParseOptions,
) => (a: A, overrideOptions?: ParseOptions) => Promise<I>;

encodeSync

Added in v3.10.0 Source

Signature

declare const encodeSync: <A, I>(
  schema: Schema.Schema<A, I, never>,
  options?: AST.ParseOptions,
) => (a: A, overrideOptions?: AST.ParseOptions) => I;

encodeUnknown

Added in v3.10.0 Source

Signature

declare function encodeUnknown<A, I, R>(
  schema: Schema<A, I, R>,
  options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => Effect<I, ParseError, R>;

Signature

declare function encodeUnknownEither<A, I>(
  schema: Schema<A, I, never>,
  options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => Either<I, ParseError>;

Signature

declare function encodeUnknownOption<A, I>(
  schema: Schema<A, I, never>,
  options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => Option<I>;

Signature

declare function encodeUnknownPromise<A, I>(
  schema: Schema<A, I, never>,
  options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => Promise<I>;

Signature

declare function encodeUnknownSync<A, I>(
  schema: Schema<A, I, never>,
  options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => I;

serialize

Added in v3.10.0 Source

Signature

declare function serialize<A, I, R>(self: Serializable<A, I, R>): Effect<I, ParseError, R>;

serializeExit

Added in v3.10.0 Source

Signature

declare const serializeExit: {
  <SA, FA>(
    value: Exit<SA, FA>,
  ): <SI, FI, R>(
    self: WithResult<SA, SI, FA, FI, R>,
  ) => Effect<ExitEncoded<SI, FI, unknown>, ParseError, R>;
  <SA, SI, FA, FI, R>(
    self: WithResult<SA, SI, FA, FI, R>,
    value: Exit<SA, FA>,
  ): Effect<ExitEncoded<SI, FI, unknown>, ParseError, R>;
};

Signature

declare const serializeFailure: {
  <FA>(
    value: FA,
  ): <SA, SI, FI, R>(self: WithResult<SA, SI, FA, FI, R>) => Effect<FI, ParseError, R>;
  <SA, SI, FA, FI, R>(self: WithResult<SA, SI, FA, FI, R>, value: FA): Effect<FI, ParseError, R>;
};

Signature

declare const serializeSuccess: {
  <SA>(
    value: SA,
  ): <SI, FA, FI, R>(self: WithResult<SA, SI, FA, FI, R>) => Effect<SI, ParseError, R>;
  <SA, SI, FA, FI, R>(self: WithResult<SA, SI, FA, FI, R>, value: SA): Effect<SI, ParseError, R>;
};

Equivalence

equivalence

Added in v3.10.0 Source

Given a schema Schema<A, I, R>, returns an Equivalence instance for A.

Signature

declare function equivalence<A, I, R>(schema: Schema<A, I, R>): Equivalence<A>;

Exit Transformations

Exit

Added in v3.10.0 Source

Signature

declare const Exit: <A extends All, E extends All, D extends All>(__namedParameters: {
  readonly defect: D;
  readonly failure: E;
  readonly success: A;
}) => Exit<A, E, D>;

ExitFromSelf

Added in v3.10.0 Source

Signature

declare const ExitFromSelf: <A extends All, E extends All, D extends All>(__namedParameters: {
  readonly defect: D;
  readonly failure: E;
  readonly success: A;
}) => ExitFromSelf<A, E, D>;

Exit Utils

ExitEncoded type

Added in v3.10.0 Source

Signature

type ExitEncoded<A, E, D> =
  | {
      readonly _tag: "Failure";
      readonly cause: CauseEncoded<E, D>;
    }
  | {
      readonly _tag: "Success";
      readonly value: A;
    };

FiberId

FiberIdEncoded type

Added in v3.10.0 Source

Signature

type FiberIdEncoded =
  | {
      readonly _tag: "Composite";
      readonly left: FiberIdEncoded;
      readonly right: FiberIdEncoded;
    }
  | {
      readonly _tag: "None";
    }
  | {
      readonly _tag: "Runtime";
      readonly id: number;
      readonly startTimeMillis: number;
    };

FiberId Constructors

Signature

declare class FiberIdFromSelf extends Variance<FiberId, FiberId, never, this> {
  constructor(_: never);
}

FiberId Transformations

FiberId

Added in v3.10.0 Source

Signature

declare class FiberId extends Variance<FiberId, FiberIdEncoded, never, this> {
  constructor(_: never);
}

Filtering

filter

Added in v3.10.0 Source

Signature

declare function filter<C, B, A = C>(
  refinement: (a: A, options: ParseOptions, self: Refinement) => a is B,
  annotations?: Filter<C & B, C>,
): <I, R>(self: Schema<C, I, R>) => refine<C & B, Schema<A, I, R>>;
declare function filter<A, B>(
  refinement: (a: A, options: ParseOptions, self: Refinement) => a is B,
  annotations?: Filter<B, A>,
): <I, R>(self: Schema<A, I, R>) => refine<B, Schema<A, I, R>>;
declare function filter<S extends Any>(
  predicate: (a: NoInfer<Type<S>>, options: ParseOptions, self: Refinement) => FilterReturnType,
  annotations?: Filter<NoInfer<Type<S>>, NoInfer<Type<S>>>,
): (self: S) => filter<S>;

FilterIssue interface

Added in v3.10.0 Source

Signature

interface FilterIssue {
  readonly message: string;
  readonly path: readonly Array<PropertyKey>;
}

FilterOutput type

Added in v3.10.0 Source

Signature

type FilterOutput = undefined | boolean | string | ParseResult.ParseIssue | FilterIssue;

Formatting

format

Added in v3.10.0 Source

Signature

declare function format<S extends All>(schema: S): string;

Guards

Signature

declare function isPropertySignature(u: unknown): u is All<PropertyKey>;

isSchema

Added in v3.10.0 Source

Tests if a value is a Schema.

Signature

declare function isSchema(u: unknown): u is Any;

HashMap Transformations

HashMap

Added in v3.10.0 Source

Signature

declare const HashMap: <K extends Any, V extends Any>(__namedParameters: {
  readonly key: K;
  readonly value: V;
}) => HashMap<K, V>;

Signature

declare const HashMapFromSelf: <K extends Any, V extends Any>(__namedParameters: {
  readonly key: K;
  readonly value: V;
}) => HashMapFromSelf<K, V>;

HashSet Transformations

HashSet

Added in v3.10.0 Source

Signature

declare function HashSet<Value extends Any>(value: Value): HashSet<Value>;

Signature

declare const HashSetFromSelf: <Value extends Any>(value: Value) => HashSetFromSelf<Value>;

List Transformations

List

Added in v3.10.0 Source

Signature

declare function List<Value extends Any>(value: Value): List<Value>;

ListFromSelf

Added in v3.10.0 Source

Signature

declare const ListFromSelf: <Value extends Any>(value: Value) => ListFromSelf<Value>;

Map

MapFromSelf

Added in v3.10.0 Source

Signature

declare const MapFromSelf: <K extends Any, V extends Any>(__namedParameters: {
  readonly key: K;
  readonly value: V;
}) => MapFromSelf<K, V>;

Map Transformations

MapFromRecord

Added in v3.10.0 Source

Signature

declare function MapFromRecord<KA, KR, VA, VI, VR>(__namedParameters: {
  key: Schema<KA, string, KR>;
  value: Schema<VA, VI, VR>;
}): SchemaClass<
  Map<KA, VA>,
  {
    [x: string]: VI;
  },
  KR | VR
>;

Model

Schema interface

Added in v3.10.0 Source

Signature

interface Schema<in out A, in out I = A, out R = never> extends Variance<A, I, R>, Pipeable {
  readonly ast: AST;
  readonly Context: R;
  readonly Encoded: I;
  readonly Type: A;
  annotations(annotations: GenericSchema<A>): Schema<A, I, R>;
}

SchemaClass interface

Added in v3.10.0 Source

Signature

interface SchemaClass<A, I = A, R = never> extends AnnotableClass<SchemaClass<A, I, R>, A, I, R> {
  constructor(_: never);
}

Serializable

Added in v3.10.0 Source

Serializable interface

Added in v3.10.0 Source

The Serializable trait allows objects to define their own schema for serialization.

Signature

interface Serializable<A, I, R> {
  readonly [symbolSerializable]: Schema<A, I, R>;
}

SerializableWithResult interface

Added in v3.10.0 Source

The SerializableWithResult trait is specifically designed to model remote procedures that require serialization of their input and output, managing both successful and failed outcomes.

This trait combines functionality from both the Serializable and WithResult traits to handle data serialization and the bifurcation of operation results into success or failure categories.

Signature

interface SerializableWithResult<A, I, R, Success, SuccessEncoded, Failure, FailureEncoded, ResultR>
  extends
    Serializable<A, I, R>,
    WithResult<Success, SuccessEncoded, Failure, FailureEncoded, ResultR> {}

WithResult

Added in v3.10.0 Source

WithResult interface

Added in v3.10.0 Source

The WithResult trait is designed to encapsulate the outcome of an operation, distinguishing between success and failure cases. Each case is associated with a schema that defines the structure and types of the success or failure data.

Signature

interface WithResult<Success, SuccessEncoded, Failure, FailureEncoded, ResultR> {
  readonly [symbolWithResult]: {
    readonly failure: Schema<Failure, FailureEncoded, ResultR>;
    readonly success: Schema<Success, SuccessEncoded, ResultR>;
  };
}

NonEmptyReadonlyArray Transformations

headNonEmpty

Added in v3.12.0 Source

Get the first element of a NonEmptyReadonlyArray.

Signature

declare function headNonEmpty<S extends Any, A extends readonly [unknown, unknown]>(
  self: S & Schema<A, Encoded<S>, Context<S>>,
): transform<S, SchemaClass<A[number], A[number], never>>;

Number Constructors

Finite

Added in v3.10.0 Source

Signature

declare class Finite extends Variance<number, number, never, this> {
  constructor(_: never);
}

Int

Added in v3.10.0 Source

Signature

declare class Int extends Variance<number, number, never, this> {
  constructor(_: never);
}

JsonNumber

Added in v3.10.0 Source

The JsonNumber is a schema for representing JSON numbers. It ensures that the provided value is a valid number by filtering out NaN and (+/-) Infinity. This is useful when you want to validate and represent numbers in JSON format.

Signature

declare class JsonNumber extends Variance<number, number, never, this> {
  constructor(_: never);
}

Example

import * as assert from "node:assert"
import * as Schema from "effect/Schema"

const is = Schema.is(Schema.JsonNumber)

assert.deepStrictEqual(is(42), true)
assert.deepStrictEqual(is(Number.NaN), false)
assert.deepStrictEqual(is(Number.POSITIVE_INFINITY), false)
assert.deepStrictEqual(is(Number.NEGATIVE_INFINITY), false)

Negative

Added in v3.10.0 Source

Signature

declare class Negative extends Variance<number, number, never, this> {
  constructor(_: never);
}

NonNaN

Added in v3.10.0 Source

Signature

declare class NonNaN extends Variance<number, number, never, this> {
  constructor(_: never);
}

NonNegative

Added in v3.10.0 Source

Signature

declare class NonNegative extends Variance<number, number, never, this> {
  constructor(_: never);
}

NonNegativeInt

Added in v3.11.10 Source

A non-negative integer. +Infinity is excluded.

Signature

declare const NonNegativeInt: refine<number, typeof NonNegative>;

NonPositive

Added in v3.10.0 Source

Signature

declare class NonPositive extends Variance<number, number, never, this> {
  constructor(_: never);
}

Positive

Added in v3.10.0 Source

Signature

declare class Positive extends Variance<number, number, never, this> {
  constructor(_: never);
}

Uint8

Added in v3.11.10 Source

Signature

declare class Uint8 extends Variance<number, number, never, this> {
  constructor(_: never);
}

Number Filters

between

Added in v3.10.0 Source

This filter checks whether the provided number falls within the specified minimum and maximum values.

Signature

declare function between<S extends Any>(
  minimum: number,
  maximum: number,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends number>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

finite

Added in v3.10.0 Source

Ensures that the provided value is a finite number (excluding NaN, +Infinity, and -Infinity).

Signature

declare function finite<S extends Any>(
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends number>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

greaterThan

Added in v3.10.0 Source

This filter checks whether the provided number is greater than the specified minimum.

Signature

declare function greaterThan<S extends Any>(
  exclusiveMinimum: number,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends number>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

This filter checks whether the provided number is greater than or equal to the specified minimum.

Signature

declare function greaterThanOrEqualTo<S extends Any>(
  minimum: number,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends number>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

int

Added in v3.10.0 Source

Ensures that the provided value is an integer number (excluding NaN, +Infinity, and -Infinity).

Signature

declare function int<S extends Any>(
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends number>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

lessThan

Added in v3.10.0 Source

This filter checks whether the provided number is less than the specified maximum.

Signature

declare function lessThan<S extends Any>(
  exclusiveMaximum: number,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends number>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

This schema checks whether the provided number is less than or equal to the specified maximum.

Signature

declare function lessThanOrEqualTo<S extends Any>(
  maximum: number,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends number>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

multipleOf

Added in v3.10.0 Source

Signature

declare function multipleOf<S extends Any>(
  divisor: number,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends number>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

negative

Added in v3.10.0 Source

Signature

declare function negative<S extends Any>(
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends number>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

nonNaN

Added in v3.10.0 Source

Signature

declare function nonNaN<S extends Any>(
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends number>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

nonNegative

Added in v3.10.0 Source

Signature

declare function nonNegative<S extends Any>(
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends number>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

nonPositive

Added in v3.10.0 Source

Signature

declare function nonPositive<S extends Any>(
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends number>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

positive

Added in v3.10.0 Source

Signature

declare function positive<S extends Any>(
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends number>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

Number Transformations

clamp

Added in v3.10.0 Source

Clamps a number between a minimum and a maximum value.

Signature

declare function clamp(
  minimum: number,
  maximum: number,
): <S extends Any, A extends number>(
  self: S & Schema<A, Encoded<S>, Context<S>>,
) => transform<S, filter<SchemaClass<A, A, never>>>;

This schema transforms a string into a number by parsing the string using the parse function of the effect/Number module.

It returns an error if the value can't be converted (for example when non-numeric characters are provided).

The following special string values are supported: "NaN", "Infinity", "-Infinity".

Signature

declare class NumberFromString extends Variance<number, string, never, this> {
  constructor(_: never);
}

parseNumber

Added in v3.10.0 Source

Transforms a string into a number by parsing the string using the parse function of the effect/Number module.

It returns an error if the value can't be converted (for example when non-numeric characters are provided).

The following special string values are supported: "NaN", "Infinity", "-Infinity".

Signature

declare function parseNumber<S extends Any, A extends string>(
  self: S & Schema<A, Encoded<S>, Context<S>>,
): transformOrFail<S, typeof Number$>;

Option Transformations

Option

Added in v3.10.0 Source

Signature

declare function Option<Value extends Any>(value: Value): Option<Value>;

Transforms strings into an Option type, effectively filtering out empty or whitespace-only strings by trimming them and checking their length. Returns none for invalid inputs and some for valid non-empty strings.

Signature

declare class OptionFromNonEmptyTrimmedString extends Variance<
  Option<string>,
  string,
  never,
  this
> {
  constructor(_: never);
}

Example

import { Schema } from "effect"

console.log(Schema.decodeSync(Schema.OptionFromNonEmptyTrimmedString)("")) // Option.none()
console.log(Schema.decodeSync(Schema.OptionFromNonEmptyTrimmedString)(" a ")) // Option.some("a")
console.log(Schema.decodeSync(Schema.OptionFromNonEmptyTrimmedString)("a")) // Option.some("a")

Signature

declare function OptionFromNullishOr<Value extends Any>(
  value: Value,
  onNoneEncoding: null | undefined,
): OptionFromNullishOr<Value>;

Signature

declare function OptionFromNullOr<Value extends Any>(value: Value): OptionFromNullOr<Value>;

OptionFromSelf

Added in v3.10.0 Source

Signature

declare const OptionFromSelf: <Value extends Any>(value: Value) => OptionFromSelf<Value>;

Signature

declare function OptionFromUndefinedOr<Value extends Any>(
  value: Value,
): OptionFromUndefinedOr<Value>;

Option Utils

OptionEncoded type

Added in v3.10.0 Source

Signature

type OptionEncoded<I> =
  | {
      readonly _tag: "None";
    }
  | {
      readonly _tag: "Some";
      readonly value: I;
    };

Other

asSchema

Added in v3.10.0 Source

Signature

declare function asSchema<S extends All>(schema: S): Schema<Type<S>, Encoded<S>, Context<S>>;

asSerializable

Added in v3.10.0 Source

Signature

declare function asSerializable<S extends All>(
  serializable: S,
): Serializable<Type<S>, Encoded<S>, Context<S>>;

Signature

declare function asSerializableWithResult<SWR extends All>(
  procedure: SWR,
): SerializableWithResult<
  Type<SWR>,
  Encoded<SWR>,
  Context<SWR>,
  Success<SWR>,
  SuccessEncoded<SWR>,
  Failure<SWR>,
  FailureEncoded<SWR>,
  Context<SWR>
>;

asWithResult

Added in v3.10.0 Source

Signature

declare function asWithResult<WR extends All>(
  withExit: WR,
): WithResult<Success<WR>, SuccessEncoded<WR>, Failure<WR>, FailureEncoded<WR>, Context<WR>>;

element

Added in v3.10.0 Source

Signature

declare function element<S extends Any>(self: S): Element<S, "">;

Element

Added in v3.10.0 Source

The encodedBoundSchema function is similar to encodedSchema but preserves the refinements up to the first transformation point in the original schema.

Signature

declare function encodedBoundSchema<A, I, R>(schema: Schema<A, I, R>): SchemaClass<I>;

encodedSchema

Added in v3.10.0 Source

The encodedSchema function allows you to extract the Encoded portion of a schema, creating a new schema that conforms to the properties defined in the original schema without retaining any refinements or transformations that were applied previously.

Signature

declare function encodedSchema<A, I, R>(schema: Schema<A, I, R>): SchemaClass<I>;

EnumsDefinition type

Added in v3.10.0 Source

Signature

type EnumsDefinition = {
  [x: string]: string | number;
};

IndexSignature

Added in v3.10.0 Source

Signature

declare function optionalElement<S extends Any>(self: S): Element<S, "?">;

OptionalOptions type

Added in v3.10.0 Source

Signature

type OptionalOptions<A> =
  | {
      readonly as?: never;
      readonly default?: never;
      readonly exact?: true;
      readonly nullable?: true;
    }
  | {
      readonly as?: never;
      readonly default: LazyArg<A>;
      readonly exact?: true;
      readonly nullable?: true;
    }
  | {
      readonly as: "Option";
      readonly default?: never;
      readonly exact?: never;
      readonly nullable?: never;
      readonly onNoneEncoding?: LazyArg<option_.Option<undefined>>;
    }
  | {
      readonly as: "Option";
      readonly default?: never;
      readonly exact?: never;
      readonly nullable: true;
      readonly onNoneEncoding?: LazyArg<option_.Option<null | undefined>>;
    }
  | {
      readonly as: "Option";
      readonly default?: never;
      readonly exact: true;
      readonly nullable?: never;
      readonly onNoneEncoding?: never;
    }
  | {
      readonly as: "Option";
      readonly default?: never;
      readonly exact: true;
      readonly nullable: true;
      readonly onNoneEncoding?: LazyArg<option_.Option<null>>;
    }
  | undefined;

ParseJsonOptions type

Added in v3.10.0 Source

Signature

type ParseJsonOptions = {
  readonly replacer?: Parameters<typeof JSON.stringify>[1];
  readonly reviver?: Parameters<typeof JSON.parse>[1];
  readonly space?: Parameters<typeof JSON.stringify>[2];
};

Schema

Added in v3.10.0 Source

Simplify type

Added in v3.10.0 Source

Signature

type Simplify<A> = { [K in keyof A]: A[K] } & {};

SimplifyMutable type

Added in v3.10.0 Source

Signature

type SimplifyMutable<A> = { [K in keyof A]: A[K] } extends infer B ? B : never;

Struct

Added in v3.10.0 Source

tag

Added in v3.10.0 Source

Returns a property signature that represents a tag. A tag is a literal value that is used to distinguish between different types of objects. The tag is optional when using the make method.

See

Signature

declare const tag: <Tag extends LiteralValue>(tag: Tag) => tag<Tag>;

Example

import * as assert from "node:assert"
import { Schema } from "effect"

const User = Schema.Struct({
  _tag: Schema.tag("User"),
  name: Schema.String,
  age: Schema.Number,
})

assert.deepStrictEqual(User.make({ name: "John", age: 44 }), {
  _tag: "User",
  name: "John",
  age: 44,
})

TaggedRequest

Added in v3.10.0 Source

TaggedRequest interface

Added in v3.10.0 Source

Signature

interface TaggedRequest<
  Tag extends string,
  A,
  I,
  R,
  SuccessType,
  SuccessEncoded,
  FailureType,
  FailureEncoded,
  ResultR,
>
  extends
    Request<SuccessType, FailureType>,
    SerializableWithResult<
      A,
      I,
      R,
      SuccessType,
      SuccessEncoded,
      FailureType,
      FailureEncoded,
      ResultR
    > {
  readonly _tag: Tag;
}

TupleType

Added in v3.10.0 Source

TypeLiteral

Added in v3.10.0 Source

typeSchema

Added in v3.10.0 Source

The typeSchema function allows you to extract the Type portion of a schema, creating a new schema that conforms to the properties defined in the original schema without considering the initial encoding or transformation processes.

Signature

declare function typeSchema<A, I, R>(schema: Schema<A, I, R>): SchemaClass<A>;

Primitives

Any

Added in v3.10.0 Source

Signature

declare class Any extends Variance<any, any, never, this> {
  constructor(_: never);
}

BigIntFromSelf

Added in v3.10.0 Source

Signature

declare class BigIntFromSelf extends Variance<bigint, bigint, never, this> {
  constructor(_: never);
}

Never

Added in v3.10.0 Source

Signature

declare class Never extends Variance<never, never, never, this> {
  constructor(_: never);
}

Null

Added in v3.10.0 Source

Signature

declare class Null extends Variance<null, null, never, this> {
  constructor(_: never);
}

SymbolFromSelf

Added in v3.10.0 Source

Signature

declare class SymbolFromSelf extends Variance<symbol, symbol, never, this> {
  constructor(_: never);
}

Undefined

Added in v3.10.0 Source

Signature

declare class Undefined extends Variance<undefined, undefined, never, this> {
  constructor(_: never);
}

Unknown

Added in v3.10.0 Source

Signature

declare class Unknown extends Variance<unknown, unknown, never, this> {
  constructor(_: never);
}

Void

Added in v3.10.0 Source

Signature

declare class Void extends Variance<void, void, never, this> {
  constructor(_: never);
}

PropertySignature

fromKey

Added in v3.10.0 Source

Enhances a property signature by specifying a different key for it in the Encoded type.

Signature

declare const fromKey: {
  <Key extends PropertyKey>(
    key: Key,
  ): <
    TypeToken extends Token,
    Type,
    EncodedToken extends Token,
    Encoded,
    HasDefault extends boolean,
    R,
  >(
    self: PropertySignature<TypeToken, Type, PropertyKey, EncodedToken, Encoded, HasDefault, R>,
  ) => PropertySignature<TypeToken, Type, Key, EncodedToken, Encoded, HasDefault, R>;
  <
    Type,
    TypeToken extends Token,
    Encoded,
    EncodedToken extends Token,
    HasDefault extends boolean,
    R,
    Key extends PropertyKey,
  >(
    self: PropertySignature<TypeToken, Type, PropertyKey, EncodedToken, Encoded, HasDefault, R>,
    key: Key,
  ): PropertySignature<TypeToken, Type, Key, EncodedToken, Encoded, HasDefault, R>;
};

Signature

declare class FromPropertySignature extends OptionalType {
  constructor(
    type: AST,
    isOptional: boolean,
    isReadonly: boolean,
    annotations: Annotations,
    fromKey?: PropertyKey,
  );
  readonly fromKey?: PropertyKey;
  readonly isReadonly: boolean;
}

Signature

declare function makePropertySignature<
  TypeToken extends Token,
  Type,
  Key extends PropertyKey,
  EncodedToken extends Token,
  Encoded,
  HasDefault extends boolean = false,
  R = never,
>(ast: AST): PropertySignatureImpl<TypeToken, Type, Key, EncodedToken, Encoded, HasDefault, R>;

optional

Added in v3.10.0 Source

Signature

declare const optional: <S extends All>(self: S) => optional<S>;

Converts an optional property to another optional property through a transformation Option -> Option.

- decode: - none as argument means the value is missing in the input. - none as return value means the value will be missing in the output. - encode: - none as argument means the value is missing in the input. - none as return value means the value will be missing in the output.

Signature

declare function optionalToOptional<FA, FI, FR, TA, TI, TR>(
  from: Schema<FA, FI, FR>,
  to: Schema<TA, TI, TR>,
  options: {
    readonly decode: (o: Option<FA>) => Option<TI>;
    readonly encode: (o: Option<TI>) => Option<FA>;
  },
): PropertySignature<"?:", TA, never, "?:", FI, false, FR | TR>;

Converts an optional property to a required one through a transformation Option -> Type.

- decode: none as argument means the value is missing in the input. - encode: none as return value means the value will be missing in the output.

Signature

declare function optionalToRequired<FA, FI, FR, TA, TI, TR>(
  from: Schema<FA, FI, FR>,
  to: Schema<TA, TI, TR>,
  options: {
    readonly decode: (o: Option<FA>) => TI;
    readonly encode: (ti: TI) => Option<FA>;
  },
): PropertySignature<":", TA, never, "?:", FI, false, FR | TR>;

optionalWith

Added in v3.10.0 Source

Signature

declare const optionalWith: {
  <S extends All, Options extends OptionalOptions<Type<S>>>(
    options: Options,
  ): (self: S) => optionalWith<S, Options>;
  <S extends All, Options extends OptionalOptions<Type<S>>>(
    self: S,
    options: Options,
  ): optionalWith<S, Options>;
};

Lifts a Schema into a PropertySignature.

Signature

declare const propertySignature: <S extends All>(self: S) => propertySignature<S>;

PropertySignature interface

Added in v3.10.0 Source

Signature

interface PropertySignature<
  TypeToken extends PropertySignature.Token,
  Type,
  Key extends PropertyKey,
  EncodedToken extends PropertySignature.Token,
  Encoded,
  HasDefault extends boolean = false,
  R = never,
>
  extends Variance<Type, Encoded, R>, Pipeable {
  readonly _EncodedToken: EncodedToken;
  readonly _HasDefault: HasDefault;
  readonly _Key: Key;
  readonly _TypeToken: TypeToken;
  readonly [PropertySignatureTypeId]: null;
  readonly ast: AST;
  annotations(
    annotations: Annotations<Type>,
  ): PropertySignature<TypeToken, Type, Key, EncodedToken, Encoded, HasDefault, R>;
}

Signature

declare class PropertySignatureDeclaration extends OptionalType {
  constructor(
    type: AST,
    isOptional: boolean,
    isReadonly: boolean,
    annotations: Annotations,
    defaultValue: () => unknown | undefined,
  );
  readonly _tag: "PropertySignatureDeclaration";
  readonly defaultValue: () => unknown | undefined;
  readonly isReadonly: boolean;
  toString(): string;
}

Signature

declare class PropertySignatureTransformation {
  constructor(
    from: FromPropertySignature,
    to: ToPropertySignature,
    decode: (o: Option<any>) => Option<any>,
    encode: (o: Option<any>) => Option<any>,
  );
  readonly _tag: "PropertySignatureTransformation";
  readonly decode: (o: Option<any>) => Option<any>;
  readonly encode: (o: Option<any>) => Option<any>;
  readonly from: FromPropertySignature;
  readonly to: ToPropertySignature;
  toString(): string;
}

Converts an optional property to a required one through a transformation Type -> Option.

- decode: none as return value means the value will be missing in the output. - encode: none as argument means the value is missing in the input.

Signature

declare function requiredToOptional<FA, FI, FR, TA, TI, TR>(
  from: Schema<FA, FI, FR>,
  to: Schema<TA, TI, TR>,
  options: {
    readonly decode: (fa: FA) => Option<TI>;
    readonly encode: (o: Option<TI>) => FA;
  },
): PropertySignature<"?:", TA, never, ":", FI, false, FR | TR>;

Signature

declare class ToPropertySignature extends OptionalType {
  constructor(
    type: AST,
    isOptional: boolean,
    isReadonly: boolean,
    annotations: Annotations,
    defaultValue: () => unknown | undefined,
  );
  readonly defaultValue: () => unknown | undefined;
  readonly isReadonly: boolean;
}

Enhances a property signature with a default constructor value.

Signature

declare const withConstructorDefault: {
  <Type>(
    defaultValue: () => NoInfer<Type>,
  ): <TypeToken extends Token, Key extends PropertyKey, EncodedToken extends Token, Encoded, R>(
    self: PropertySignature<TypeToken, Type, Key, EncodedToken, Encoded, boolean, R>,
  ) => PropertySignature<TypeToken, Type, Key, EncodedToken, Encoded, true, R>;
  <TypeToken extends Token, Type, Key extends PropertyKey, EncodedToken extends Token, Encoded, R>(
    self: PropertySignature<TypeToken, Type, Key, EncodedToken, Encoded, boolean, R>,
    defaultValue: () => NoInfer<Type>,
  ): PropertySignature<TypeToken, Type, Key, EncodedToken, Encoded, true, R>;
};

Enhances a property signature with a default decoding value.

Signature

declare const withDecodingDefault: {
  <Type>(
    defaultValue: () => NoInfer<Exclude<Type, undefined>>,
  ): <Key extends PropertyKey, Encoded, R>(
    self: PropertySignature<"?:", Type, Key, "?:", Encoded, false, R>,
  ) => PropertySignature<":", Exclude<Type, undefined>, Key, "?:", Encoded, false, R>;
  <Type, Key extends PropertyKey, Encoded, R>(
    self: PropertySignature<"?:", Type, Key, "?:", Encoded, false, R>,
    defaultValue: () => NoInfer<Exclude<Type, undefined>>,
  ): PropertySignature<":", Exclude<Type, undefined>, Key, "?:", Encoded, false, R>;
};

withDefaults

Added in v3.10.0 Source

Enhances a property signature with a default decoding value and a default constructor value.

Signature

declare const withDefaults: {
  <Type>(defaults: {
    constructor: () => Types.NoInfer<Exclude<Type, undefined>>;
    decoding: () => Types.NoInfer<Exclude<Type, undefined>>;
  }): <Key extends PropertyKey, Encoded, R>(
    self: PropertySignature<"?:", Type, Key, "?:", Encoded, boolean, R>,
  ) => PropertySignature<":", Exclude<Type, undefined>, Key, "?:", Encoded, true, R>;
  <Type, Key extends PropertyKey, Encoded, R>(
    self: PropertySignature<"?:", Type, Key, "?:", Encoded, boolean, R>,
    defaults: {
      constructor: () => Types.NoInfer<Exclude<Type, undefined>>;
      decoding: () => Types.NoInfer<Exclude<Type, undefined>>;
    },
  ): PropertySignature<":", Exclude<Type, undefined>, Key, "?:", Encoded, true, R>;
};

ReadonlyArray Filters

itemsCount

Added in v3.10.0 Source

Signature

declare function itemsCount<S extends Any>(n: number, annotations?: Filter<Type<S>, Type<S>>): <A extends readonly Array<any>>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>

maxItems

Added in v3.10.0 Source

Signature

declare function maxItems<S extends Any>(n: number, annotations?: Filter<Type<S>, Type<S>>): <A extends readonly Array<any>>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>

minItems

Added in v3.10.0 Source

Signature

declare function minItems<S extends Any>(n: number, annotations?: Filter<Type<S>, Type<S>>): <A extends readonly Array<any>>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>

ReadonlyArray Transformations

Signature

declare function getNumberIndexedAccess<A extends readonly Array<any>, I extends readonly Array<any>, R>(self: Schema<A, I, R>): SchemaClass<A[number], I[number], R>

headOrElse

Added in v3.10.0 Source

Retrieves the first element of a ReadonlyArray.

If the array is empty, it returns the fallback argument if provided; otherwise, it fails.

Signature

declare const headOrElse: {
  <S extends Any, A extends readonly Array<unknown>>(fallback?: LazyArg<A[number]>): (self: S & Schema<A, Encoded<S>, Context<S>>) => transform<S, SchemaClass<A[number], A[number], never>>;
  <S extends Any, A extends readonly Array<unknown>>(self: S & Schema<A, Encoded<S>, Context<S>>, fallback?: LazyArg<A[number]>): transform<S, SchemaClass<A[number], A[number], never>>;
}

ReadonlyMap

Signature

declare const ReadonlyMapFromSelf: <K extends Any, V extends Any>(__namedParameters: {
  readonly key: K;
  readonly value: V;
}) => ReadonlyMapFromSelf<K, V>;

ReadonlyMap Transformations

ReadonlyMap

Added in v3.10.0 Source

Signature

declare function ReadonlyMap<K extends Any, V extends Any>(__namedParameters: {
  readonly key: K;
  readonly value: V;
}): ReadonlyMap$<K, V>;

Signature

declare function ReadonlyMapFromRecord<KA, KR, VA, VI, VR>(__namedParameters: {
  key: Schema<KA, string, KR>;
  value: Schema<VA, VI, VR>;
}): SchemaClass<
  ReadonlyMap<KA, VA>,
  {
    [x: string]: VI;
  },
  KR | VR
>;

ReadonlySet

Signature

declare const ReadonlySetFromSelf: <Value extends Any>(value: Value) => ReadonlySetFromSelf<Value>;

ReadonlySet Transformations

ReadonlySet

Added in v3.10.0 Source

Signature

declare function ReadonlySet<Value extends Any>(value: Value): ReadonlySet$<Value>;

Redacted Constructors

Signature

declare const RedactedFromSelf: <Value extends Any>(value: Value) => RedactedFromSelf<Value>;

Redacted Transformations

Redacted

Added in v3.10.0 Source

A transformation that transform a Schema<A, I, R> into a RedactedFromSelf<A>.

Signature

declare function Redacted<Value extends Any>(value: Value): Redacted<Value>;

Renaming

rename

Added in v3.10.0 Source

Signature

declare const rename: {
  <
    A,
    M extends { [K in string | number | symbol]: PropertyKey } & {
      [K in string | number | symbol]: never;
    },
  >(
    mapping: M,
  ): <I, R>(
    self: Schema<A, I, R>,
  ) => SchemaClass<{ [K in string | number | symbol]: Rename<A, M>[K] }, I, R>;
  <
    A,
    I,
    R,
    M extends { [K in string | number | symbol]: PropertyKey } & {
      [K in string | number | symbol]: never;
    },
  >(
    self: Schema<A, I, R>,
    mapping: M,
  ): SchemaClass<{ [K in string | number | symbol]: Rename<A, M>[K] }, I, R>;
};

Schema Id

Signature

declare const BetweenBigDecimalSchemaId: unique symbol;

Signature

declare const BetweenBigIntSchemaId: unique symbol;

BetweenBigIntSchemaId type

Added in v3.10.0 Source

Signature

type BetweenBigIntSchemaId = typeof BetweenBigIntSchemaId;

Signature

declare const BetweenDateSchemaId: unique symbol;

Signature

declare const BetweenDurationSchemaId: unique symbol;

Signature

declare const BetweenSchemaId: unique symbol;

BetweenSchemaId type

Added in v3.10.0 Source

Signature

type BetweenSchemaId = typeof BetweenSchemaId;

BrandSchemaId

Added in v3.10.0 Source

Signature

declare const BrandSchemaId: unique symbol;

Signature

declare const CapitalizedSchemaId: unique symbol;

Signature

declare const DateFromSelfSchemaId: unique symbol;

DateFromSelfSchemaId type

Added in v3.11.8 Source

Signature

type DateFromSelfSchemaId = typeof DateFromSelfSchemaId;

Signature

declare const EndsWithSchemaId: unique symbol;

FiniteSchemaId

Added in v3.10.0 Source

Signature

declare const FiniteSchemaId: unique symbol;

FiniteSchemaId type

Added in v3.10.0 Source

Signature

type FiniteSchemaId = typeof FiniteSchemaId;

Signature

declare const GreaterThanBigDecimalSchemaId: unique symbol;

Signature

declare const GreaterThanBigIntSchemaId: unique symbol;

Signature

type GreaterThanBigIntSchemaId = typeof GreaterThanBigIntSchemaId;

Signature

declare const GreaterThanDateSchemaId: unique symbol;

Signature

declare const GreaterThanDurationSchemaId: unique symbol;

Signature

declare const GreaterThanOrEqualToBigDecimalSchemaId: unique symbol;

Signature

declare const GreaterThanOrEqualToBigIntSchemaId: unique symbol;

Signature

type GreaterThanOrEqualToBigIntSchemaId = typeof GreaterThanOrEqualToBigIntSchemaId;

Signature

declare const GreaterThanOrEqualToDateSchemaId: unique symbol;

Signature

declare const GreaterThanOrEqualToDurationSchemaId: unique symbol;

Signature

declare const GreaterThanOrEqualToSchemaId: unique symbol;

Signature

type GreaterThanOrEqualToSchemaId = typeof GreaterThanOrEqualToSchemaId;

Signature

declare const GreaterThanSchemaId: unique symbol;

GreaterThanSchemaId type

Added in v3.10.0 Source

Signature

type GreaterThanSchemaId = typeof GreaterThanSchemaId;

Signature

declare const IncludesSchemaId: unique symbol;

Signature

declare const InstanceOfSchemaId: unique symbol;

IntSchemaId

Added in v3.10.0 Source

Signature

declare const IntSchemaId: unique symbol;

IntSchemaId type

Added in v3.10.0 Source

Signature

type IntSchemaId = typeof IntSchemaId;

Signature

declare const ItemsCountSchemaId: unique symbol;

ItemsCountSchemaId type

Added in v3.10.0 Source

Signature

type ItemsCountSchemaId = typeof ItemsCountSchemaId;

Signature

declare const JsonNumberSchemaId: unique symbol;

JsonNumberSchemaId type

Added in v3.10.0 Source

Signature

type JsonNumberSchemaId = typeof JsonNumberSchemaId;

LengthSchemaId

Added in v3.10.0 Source

Signature

declare const LengthSchemaId: unique symbol;

LengthSchemaId type

Added in v3.10.0 Source

Signature

type LengthSchemaId = typeof LengthSchemaId;

Signature

declare const LessThanBigDecimalSchemaId: unique symbol;

Signature

declare const LessThanBigIntSchemaId: unique symbol;

Signature

type LessThanBigIntSchemaId = typeof LessThanBigIntSchemaId;

Signature

declare const LessThanDateSchemaId: unique symbol;

Signature

declare const LessThanDurationSchemaId: unique symbol;

Signature

declare const LessThanOrEqualToBigDecimalSchemaId: unique symbol;

Signature

declare const LessThanOrEqualToBigIntSchemaId: unique symbol;

Signature

type LessThanOrEqualToBigIntSchemaId = typeof LessThanOrEqualToBigIntSchemaId;

Signature

declare const LessThanOrEqualToDateSchemaId: unique symbol;

Signature

declare const LessThanOrEqualToDurationSchemaId: unique symbol;

Signature

declare const LessThanOrEqualToSchemaId: unique symbol;

Signature

type LessThanOrEqualToSchemaId = typeof LessThanOrEqualToSchemaId;

Signature

declare const LessThanSchemaId: unique symbol;

LessThanSchemaId type

Added in v3.10.0 Source

Signature

type LessThanSchemaId = typeof LessThanSchemaId;

Signature

declare const LowercasedSchemaId: unique symbol;

Signature

declare const MaxItemsSchemaId: unique symbol;

MaxItemsSchemaId type

Added in v3.10.0 Source

Signature

type MaxItemsSchemaId = typeof MaxItemsSchemaId;

Signature

declare const MaxLengthSchemaId: unique symbol;

MaxLengthSchemaId type

Added in v3.10.0 Source

Signature

type MaxLengthSchemaId = typeof MaxLengthSchemaId;

Signature

declare const MinItemsSchemaId: unique symbol;

MinItemsSchemaId type

Added in v3.10.0 Source

Signature

type MinItemsSchemaId = typeof MinItemsSchemaId;

Signature

declare const MinLengthSchemaId: unique symbol;

MinLengthSchemaId type

Added in v3.10.0 Source

Signature

type MinLengthSchemaId = typeof MinLengthSchemaId;

Signature

declare const MultipleOfSchemaId: unique symbol;

Signature

declare const NegativeBigDecimalSchemaId: unique symbol;

NonNaNSchemaId

Added in v3.10.0 Source

Signature

declare const NonNaNSchemaId: unique symbol;

NonNaNSchemaId type

Added in v3.10.0 Source

Signature

type NonNaNSchemaId = typeof NonNaNSchemaId;

Signature

declare const NonNegativeBigDecimalSchemaId: unique symbol;

Signature

declare const NonPositiveBigDecimalSchemaId: unique symbol;

Signature

declare const PatternSchemaId: unique symbol;

Signature

declare const PositiveBigDecimalSchemaId: unique symbol;

Signature

declare const StartsWithSchemaId: unique symbol;

Signature

declare const TrimmedSchemaId: unique symbol;

ULIDSchemaId

Added in v3.10.0 Source

Signature

declare const ULIDSchemaId: unique symbol;

Signature

declare const UncapitalizedSchemaId: unique symbol;

Signature

declare const UppercasedSchemaId: unique symbol;

UUIDSchemaId

Added in v3.10.0 Source

Signature

declare const UUIDSchemaId: unique symbol;

Signature

declare const ValidDateSchemaId: unique symbol;

Set

SetFromSelf

Added in v3.10.0 Source

Signature

declare const SetFromSelf: <Value extends Any>(value: Value) => SetFromSelf<Value>;

SortedSet Transformations

SortedSet

Added in v3.10.0 Source

Signature

declare function SortedSet<Value extends Any>(
  value: Value,
  ordA: Order<Type<Value>>,
): SortedSet<Value>;

Signature

declare const SortedSetFromSelf: <Value extends Any>(
  value: Value,
  ordA: Order<Type<Value>>,
  ordI: Order<Encoded<Value>>,
) => SortedSetFromSelf<Value>;

Standard Schema

Returns a "Standard Schema" object conforming to the [Standard Schema v1](https://standardschema.dev/) specification.

This function creates a schema whose validate method attempts to decode and validate the provided input synchronously. If the underlying Schema includes any asynchronous components (e.g., asynchronous message resolutions or checks), then validation will necessarily return a Promise instead.

Any detected defects will be reported via a single issue containing no path.

Signature

declare function standardSchemaV1<A, I>(
  schema: Schema<A, I, never>,
  overrideOptions?: ParseOptions,
): any;

String Constructors

Capitalized

Added in v3.10.0 Source

Signature

declare class Capitalized extends Variance<string, string, never, this> {
  constructor(_: never);
}

Char

Added in v3.10.0 Source

A schema representing a single character.

Signature

declare class Char extends Variance<string, string, never, this> {
  constructor(_: never);
}

Lowercased

Added in v3.10.0 Source

Signature

declare class Lowercased extends Variance<string, string, never, this> {
  constructor(_: never);
}

NonEmptyString

Added in v3.10.0 Source

Signature

declare class NonEmptyString extends Variance<string, string, never, this> {
  constructor(_: never);
}

Useful for validating strings that must contain meaningful characters without leading or trailing whitespace.

Signature

declare class NonEmptyTrimmedString extends Variance<string, string, never, this> {
  constructor(_: never);
}

Example

import { Schema } from "effect"

console.log(Schema.decodeOption(Schema.NonEmptyTrimmedString)("")) // Option.none()
console.log(Schema.decodeOption(Schema.NonEmptyTrimmedString)(" a ")) // Option.none()
console.log(Schema.decodeOption(Schema.NonEmptyTrimmedString)("a")) // Option.some("a")

Trimmed

Added in v3.10.0 Source

Signature

declare class Trimmed extends Variance<string, string, never, this> {
  constructor(_: never);
}

ULID

Added in v3.10.0 Source

Represents a Universally Unique Lexicographically Sortable Identifier (ULID).

ULIDs are designed to be compact, URL-safe, and ordered, making them suitable for use as identifiers. This schema ensures that the provided string adheres to the standard ULID format.

Signature

declare class ULID extends Variance<string, string, never, this> {
  constructor(_: never);
}

Uncapitalized

Added in v3.10.0 Source

Signature

declare class Uncapitalized extends Variance<string, string, never, this> {
  constructor(_: never);
}

Uppercased

Added in v3.10.0 Source

Signature

declare class Uppercased extends Variance<string, string, never, this> {
  constructor(_: never);
}

UUID

Added in v3.10.0 Source

Represents a Universally Unique Identifier (UUID).

This schema ensures that the provided string adheres to the standard UUID format.

Signature

declare class UUID extends Variance<string, string, never, this> {
  constructor(_: never);
}

String Filters

capitalized

Added in v3.10.0 Source

Verifies that a string is capitalized.

Signature

declare function capitalized<S extends Any>(
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends string>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

endsWith

Added in v3.10.0 Source

Signature

declare function endsWith<S extends Any>(
  endsWith: string,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends string>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

includes

Added in v3.10.0 Source

Signature

declare function includes<S extends Any>(
  searchString: string,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends string>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

length

Added in v3.10.0 Source

Signature

declare function length<S extends Any>(
  length:
    | number
    | {
        readonly max: number;
        readonly min: number;
      },
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends string>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

lowercased

Added in v3.10.0 Source

Verifies that a string is lowercased.

Signature

declare function lowercased<S extends Any>(
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends string>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

maxLength

Added in v3.10.0 Source

Signature

declare function maxLength<S extends Any>(
  maxLength: number,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends string>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

minLength

Added in v3.10.0 Source

Signature

declare function minLength<S extends Any>(
  minLength: number,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends string>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

nonEmptyString

Added in v3.10.0 Source

Signature

declare function nonEmptyString<S extends Any>(
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends string>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

pattern

Added in v3.10.0 Source

Signature

declare function pattern<S extends Any>(
  regex: RegExp,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends string>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

startsWith

Added in v3.10.0 Source

Signature

declare function startsWith<S extends Any>(
  startsWith: string,
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends string>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

trimmed

Added in v3.10.0 Source

Verifies that a string contains no leading or trailing whitespaces.

Note. This combinator does not make any transformations, it only validates. If what you were looking for was a combinator to trim strings, then check out the trim combinator.

Signature

declare function trimmed<S extends Any>(
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends string>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

uncapitalized

Added in v3.10.0 Source

Verifies that a string is uncapitalized.

Signature

declare function uncapitalized<S extends Any>(
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends string>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

uppercased

Added in v3.10.0 Source

Verifies that a string is uppercased.

Signature

declare function uppercased<S extends Any>(
  annotations?: Filter<Type<S>, Type<S>>,
): <A extends string>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;

String Transformations

Capitalize

Added in v3.10.0 Source

This schema converts a string to capitalized one.

Signature

declare class Capitalize extends Variance<string, string, never, this> {
  constructor(_: never);
}

Lowercase

Added in v3.10.0 Source

This schema converts a string to lowercase.

Signature

declare class Lowercase extends Variance<string, string, never, this> {
  constructor(_: never);
}

parseJson

Added in v3.10.0 Source

The ParseJson combinator provides a method to convert JSON strings into the unknown type using the underlying functionality of JSON.parse. It also utilizes JSON.stringify for encoding.

You can optionally provide a ParseJsonOptions to configure both JSON.parse and JSON.stringify executions.

Optionally, you can pass a schema Schema<A, I, R> to obtain an A type instead of unknown.

Signature

declare const parseJson: {
  <S extends Any>(
    schema: S,
    options?: ParseJsonOptions,
  ): transform<SchemaClass<unknown, string, never>, S>;
  (options?: ParseJsonOptions): SchemaClass<unknown, string>;
};

Example

import * as assert from "node:assert"
import * as Schema from "effect/Schema"

assert.deepStrictEqual(Schema.decodeUnknownSync(Schema.parseJson())(`{"a":"1"}`), { a: "1" })
assert.deepStrictEqual(
  Schema.decodeUnknownSync(Schema.parseJson(Schema.Struct({ a: Schema.NumberFromString })))(
    `{"a":"1"}`,
  ),
  { a: 1 },
)

split

Added in v3.10.0 Source

Returns a schema that allows splitting a string into an array of strings.

Signature

declare function split(
  separator: string,
): transform<SchemaClass<string, string, never>, Array$<typeof String$>>;

Decodes a base64 (RFC4648) encoded string into a UTF-8 string.

Signature

declare const StringFromBase64: Schema<string>;

Decodes a base64 (URL) encoded string into a UTF-8 string.

Signature

declare const StringFromBase64Url: Schema<string>;

StringFromHex

Added in v3.10.0 Source

Decodes a hex encoded string into a UTF-8 string.

Signature

declare const StringFromHex: Schema<string>;

Decodes a URI component encoded string into a UTF-8 string. Can be used to store data in a URL.

Signature

declare const StringFromUriComponent: transformOrFail<
  SchemaClass<string, string, never>,
  typeof String$,
  never
>;

Example

import { Schema } from "effect"

const PaginationSchema = Schema.Struct({
  maxItemPerPage: Schema.Number,
  page: Schema.Number,
})

const UrlSchema = Schema.compose(Schema.StringFromUriComponent, Schema.parseJson(PaginationSchema))

console.log(Schema.encodeSync(UrlSchema)({ maxItemPerPage: 10, page: 1 }))
// Output: %7B%22maxItemPerPage%22%3A10%2C%22page%22%3A1%7D

Trim

Added in v3.10.0 Source

This schema allows removing whitespaces from the beginning and end of a string.

Signature

declare class Trim extends Variance<string, string, never, this> {
  constructor(_: never);
}

Uncapitalize

Added in v3.10.0 Source

This schema converts a string to uncapitalized one.

Signature

declare class Uncapitalize extends Variance<string, string, never, this> {
  constructor(_: never);
}

Uppercase

Added in v3.10.0 Source

This schema converts a string to uppercase.

Signature

declare class Uppercase extends Variance<string, string, never, this> {
  constructor(_: never);
}

Struct Transformations

omit

Added in v3.10.0 Source

Signature

declare function omit<A, I, Keys extends readonly Array<keyof A & keyof I>>(...keys: Keys): <R>(self: Schema<A, I, R>) => SchemaClass<{ [K in string | number | symbol]: Omit<A, Keys[number]>[K] }, { [K in string | number | symbol]: Omit<I, Keys[number]>[K] }, R>

pick

Added in v3.10.0 Source

Signature

declare function pick<A, I, Keys extends readonly Array<keyof A & keyof I>>(...keys: Keys): <R>(self: Schema<A, I, R>) => SchemaClass<{ [K in string | number | symbol]: Pick<A, Keys[number]>[K] }, { [K in string | number | symbol]: Pick<I, Keys[number]>[K] }, R>

pluck

Added in v3.10.0 Source

Given a schema Schema<A, I, R> and a key key: K, this function extracts a specific field from the A type, producing a new schema that represents a transformation from the { readonly [key]: I[K] } type to A[K].

Signature

declare const pluck: {
  <A, I, K extends string | number | symbol>(
    key: K,
  ): <R>(
    schema: Schema<A, I, R>,
  ) => SchemaClass<A[K], { [K in string | number | symbol]: Pick<I, K>[K] }, R>;
  <A, I, R, K extends string | number | symbol>(
    schema: Schema<A, I, R>,
    key: K,
  ): SchemaClass<A[K], { [K in string | number | symbol]: Pick<I, K>[K] }, R>;
};

Example

import * as Schema from "effect/Schema"

// ---------------------------------------------
// use case: pull out a single field from a
// struct through a transformation
// ---------------------------------------------

const mytable = Schema.Struct({
  column1: Schema.NumberFromString,
  column2: Schema.Number,
})

// const pullOutColumn: S.Schema<number, {
//     readonly column1: string;
// }, never>
const pullOutColumn = mytable.pipe(Schema.pluck("column1"))

console.log(
  Schema.decodeUnknownEither(Schema.Array(pullOutColumn))([
    { column1: "1", column2: 100 },
    { column1: "2", column2: 300 },
  ]),
)
// Output: { _id: 'Either', _tag: 'Right', right: [ 1, 2 ] }

Symbol

Signature

declare const PropertySignatureTypeId: unique symbol;

Signature

type PropertySignatureTypeId = typeof PropertySignatureTypeId;

RefineSchemaId

Added in v3.10.0 Source

Signature

declare const RefineSchemaId: unique symbol;

RefineSchemaId type

Added in v3.10.0 Source

Signature

type RefineSchemaId = typeof RefineSchemaId;

Signature

declare const symbolSerializable: unique symbol;

Signature

declare const symbolWithResult: unique symbol;

TypeId

Added in v3.10.0 Source

Signature

declare const TypeId: unique symbol;

TypeId type

Added in v3.10.0 Source

Signature

type TypeId = typeof TypeId;

Template Literal

Signature

declare const TemplateLiteral: <
  Params extends readonly [TemplateLiteralParameter, TemplateLiteralParameter],
>(
  ...__namedParameters: Params
) => TemplateLiteral<GetTemplateLiteralType<Params>>;

Signature

declare const TemplateLiteralParser: <
  Params extends readonly [TemplateLiteralParserParameters, TemplateLiteralParserParameters],
>(
  ...params: Params
) => TemplateLiteralParser<Params>;

TimeZone Constructors

Signature

declare class TimeZoneFromSelf extends Variance<Offset | Named, Offset | Named, never, this> {
  constructor(_: never);
}

Describes a schema that represents a TimeZone.Named instance.

Signature

declare class TimeZoneNamedFromSelf extends Variance<Named, Named, never, this> {
  constructor(_: never);
}

Describes a schema that represents a TimeZone.Offset instance.

Signature

declare class TimeZoneOffsetFromSelf extends Variance<Offset, Offset, never, this> {
  constructor(_: never);
}

TimeZone Transformations

TimeZone

Added in v3.10.0 Source

Defines a schema that attempts to convert a string to a TimeZone using the DateTime.zoneFromString constructor.

Signature

declare class TimeZone extends Variance<Offset | Named, string, never, this> {
  constructor(_: never);
}

TimeZoneNamed

Added in v3.10.0 Source

Defines a schema that attempts to convert a string to a TimeZone.Named instance using the DateTime.zoneUnsafeMakeNamed constructor.

Signature

declare class TimeZoneNamed extends Variance<Named, string, never, this> {
  constructor(_: never);
}

TimeZoneOffset

Added in v3.10.0 Source

Defines a schema that converts a number to a TimeZone.Offset instance using the DateTime.zoneMakeOffset constructor.

Signature

declare class TimeZoneOffset extends Variance<Offset, number, never, this> {
  constructor(_: never);
}

Transformations

filterEffect

Added in v3.10.0 Source

Signature

declare const filterEffect: {
  <S extends Any, FD>(
    f: (
      a: NoInfer<Type<S>>,
      options: ParseOptions,
      self: Transformation,
    ) => Effect<FilterReturnType, never, FD>,
  ): (self: S) => filterEffect<S, FD>;
  <S extends Any, RD>(
    self: S,
    f: (
      a: NoInfer<Type<S>>,
      options: ParseOptions,
      self: Transformation,
    ) => Effect<FilterReturnType, never, RD>,
  ): filterEffect<S, RD>;
};

transform

Added in v3.10.0 Source

Create a new Schema by transforming the input and output of an existing Schema using the provided mapping functions.

Signature

declare const transform: {
  <To extends Any, From extends Any>(
    to: To,
    options:
      | {
          readonly decode: (fromA: Type<From>, fromI: Encoded<From>) => Encoded<To>;
          readonly encode: (toI: Encoded<To>, toA: Type<To>) => Type<From>;
          readonly strict?: true;
        }
      | {
          readonly decode: (fromA: Type<From>, fromI: Encoded<From>) => unknown;
          readonly encode: (toI: Encoded<To>, toA: Type<To>) => unknown;
          readonly strict: false;
        },
  ): (from: From) => transform<From, To>;
  <To extends Any, From extends Any>(
    from: From,
    to: To,
    options:
      | {
          readonly decode: (fromA: Type<From>, fromI: Encoded<From>) => Encoded<To>;
          readonly encode: (toI: Encoded<To>, toA: Type<To>) => Type<From>;
          readonly strict?: true;
        }
      | {
          readonly decode: (fromA: Type<From>, fromI: Encoded<From>) => unknown;
          readonly encode: (toI: Encoded<To>, toA: Type<To>) => unknown;
          readonly strict: false;
        },
  ): transform<From, To>;
};

Create a new Schema by transforming the input and output of an existing Schema using the provided decoding functions.

Signature

declare const transformOrFail: {
  <To extends Any, From extends Any, RD, RE>(
    to: To,
    options:
      | {
          readonly decode: (
            fromA: Type<From>,
            options: ParseOptions,
            ast: Transformation,
            fromI: Encoded<From>,
          ) => Effect<Encoded<To>, ParseIssue, RD>;
          readonly encode: (
            toI: Encoded<To>,
            options: ParseOptions,
            ast: Transformation,
            toA: Type<To>,
          ) => Effect<Type<From>, ParseIssue, RE>;
          readonly strict?: true;
        }
      | {
          readonly decode: (
            fromA: Type<From>,
            options: ParseOptions,
            ast: Transformation,
            fromI: Encoded<From>,
          ) => Effect<unknown, ParseIssue, RD>;
          readonly encode: (
            toI: Encoded<To>,
            options: ParseOptions,
            ast: Transformation,
            toA: Type<To>,
          ) => Effect<unknown, ParseIssue, RE>;
          readonly strict: false;
        },
  ): (from: From) => transformOrFail<From, To, RD | RE>;
  <To extends Any, From extends Any, RD, RE>(
    from: From,
    to: To,
    options:
      | {
          readonly decode: (
            fromA: Type<From>,
            options: ParseOptions,
            ast: Transformation,
            fromI: Encoded<From>,
          ) => Effect<Encoded<To>, ParseIssue, RD>;
          readonly encode: (
            toI: Encoded<To>,
            options: ParseOptions,
            ast: Transformation,
            toA: Type<To>,
          ) => Effect<Type<From>, ParseIssue, RE>;
          readonly strict?: true;
        }
      | {
          readonly decode: (
            fromA: Type<From>,
            options: ParseOptions,
            ast: Transformation,
            fromI: Encoded<From>,
          ) => Effect<unknown, ParseIssue, RD>;
          readonly encode: (
            toI: Encoded<To>,
            options: ParseOptions,
            ast: Transformation,
            toA: Type<To>,
          ) => Effect<unknown, ParseIssue, RE>;
          readonly strict: false;
        },
  ): transformOrFail<From, To, RD | RE>;
};

Uint8Array Constructors

Signature

declare class Uint8ArrayFromSelf extends Variance<
  Uint8Array<ArrayBufferLike>,
  Uint8Array<ArrayBufferLike>,
  never,
  this
> {
  constructor(_: never);
}

Uint8Array Transformations

Decodes a base64 (RFC4648) encoded string into a Uint8Array.

Signature

declare const Uint8ArrayFromBase64: Schema<Uint8Array, string>;

Decodes a base64 (URL) encoded string into a Uint8Array.

Signature

declare const Uint8ArrayFromBase64Url: Schema<Uint8Array, string>;

Decodes a hex encoded string into a Uint8Array.

Signature

declare const Uint8ArrayFromHex: Schema<Uint8Array, string>;

URL Constructors

URLFromSelf

Added in v3.11.0 Source

Defines a schema that represents a URL object.

Signature

declare class URLFromSelf extends Variance<URL, URL, never, this> {
  constructor(_: never);
}

Validation

asserts

Added in v3.10.0 Source

By default the option exact is set to true.

Signature

declare function asserts<A, I, R>(
  schema: Schema<A, I, R>,
  options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => asserts u is A;

is

Added in v3.10.0 Source

By default the option exact is set to true.

Signature

declare function is<A, I, R>(
  schema: Schema<A, I, R>,
  options?: ParseOptions,
): (u: unknown, overrideOptions?: number | ParseOptions) => u is A;

validate

Added in v3.10.0 Source

Signature

declare function validate<A, I, R>(
  schema: Schema<A, I, R>,
  options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => Effect<A, ParseError, R>;

validateEither

Added in v3.10.0 Source

Signature

declare function validateEither<A, I, R>(
  schema: Schema<A, I, R>,
  options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => Either<A, ParseError>;

validateOption

Added in v3.10.0 Source

Signature

declare function validateOption<A, I, R>(
  schema: Schema<A, I, R>,
  options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => Option<A>;

Signature

declare function validatePromise<A, I>(
  schema: Schema<A, I, never>,
  options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => Promise<A>;

validateSync

Added in v3.10.0 Source

Signature

declare function validateSync<A, I, R>(
  schema: Schema<A, I, R>,
  options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => A;