Skip to main content Link Search Menu Expand Document (external link)

Schema.ts overview

Since v3.10.0


Exports Grouped by Category


API interface

Element (interface)

Signature

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

Source

Since v3.10.0

TemplateLiteral (interface)

Signature

export interface TemplateLiteral<A> extends SchemaClass<A> {}

Source

Since v3.10.0

TemplateLiteralParser (interface)

Signature

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

Source

Since v3.10.0

propertySignature (interface)

Signature

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

Source

Since v1.0.0

ArrayFormatter

ArrayFormatterIssue (class)

Signature

declare class ArrayFormatterIssue

Source

Since v3.12.5

BigDecimal constructors

BigDecimalFromSelf (class)

Signature

declare class BigDecimalFromSelf

Source

Since v3.10.0

NegativeBigDecimalFromSelf

Signature

declare const NegativeBigDecimalFromSelf: filter<Schema<bigDecimal_.BigDecimal, bigDecimal_.BigDecimal, never>>

Source

Since v3.10.0

NonNegativeBigDecimalFromSelf

Signature

declare const NonNegativeBigDecimalFromSelf: filter<Schema<bigDecimal_.BigDecimal, bigDecimal_.BigDecimal, never>>

Source

Since v3.10.0

NonPositiveBigDecimalFromSelf

Signature

declare const NonPositiveBigDecimalFromSelf: filter<Schema<bigDecimal_.BigDecimal, bigDecimal_.BigDecimal, never>>

Source

Since v3.10.0

PositiveBigDecimalFromSelf

Signature

declare const PositiveBigDecimalFromSelf: filter<Schema<bigDecimal_.BigDecimal, bigDecimal_.BigDecimal, never>>

Source

Since v3.10.0

BigDecimal filters

betweenBigDecimal

Signature

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

Source

Since v3.10.0

greaterThanBigDecimal

Signature

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

Source

Since v3.10.0

greaterThanOrEqualToBigDecimal

Signature

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

Source

Since v3.10.0

lessThanBigDecimal

Signature

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

Source

Since v3.10.0

lessThanOrEqualToBigDecimal

Signature

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

Source

Since v3.10.0

negativeBigDecimal

Signature

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

Source

Since v3.10.0

nonNegativeBigDecimal

Signature

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

Source

Since v3.10.0

nonPositiveBigDecimal

Signature

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

Source

Since v3.10.0

positiveBigDecimal

Signature

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

Source

Since v3.10.0

BigDecimal transformations

BigDecimal (class)

Signature

declare class BigDecimal

Source

Since v3.10.0

BigDecimalFromNumber (class)

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

Source

Since v3.10.0

clampBigDecimal

Clamps a BigDecimal between a minimum and a maximum value.

Signature

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

Source

Since v3.10.0

Cause transformations

Cause

Signature

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

Source

Since v3.10.0

CauseFromSelf

Signature

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

Source

Since v3.10.0

Cause utils

CauseEncoded (type alias)

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>
    }

Source

Since v3.10.0

Chunk

ChunkFromSelf

Signature

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

Source

Since v3.10.0

NonEmptyChunkFromSelf

Signature

declare const NonEmptyChunkFromSelf: <Value extends Schema.Any>(value: Value) => NonEmptyChunkFromSelf<Value>

Source

Since v3.10.0

Chunk transformations

Chunk

Signature

declare const Chunk: <Value extends Schema.Any>(value: Value) => Chunk<Value>

Source

Since v3.10.0

NonEmptyChunk

Signature

declare const NonEmptyChunk: <Value extends Schema.Any>(value: Value) => NonEmptyChunk<Value>

Source

Since v3.10.0

Config validations

Config

Signature

declare const Config: <A, I extends string>(name: string, schema: Schema<A, I>) => config_.Config<A>

Source

Since v3.10.0

Constructor utils

MakeOptions (type alias)

Signature

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

Source

Since v3.13.4

Data transformations

Data

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

Signature

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

Source

Since v3.10.0

DataFromSelf

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

Signature

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

Source

Since v3.10.0

Date constructors

DateFromSelf (class)

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

Signature

declare class DateFromSelf

Source

Since v3.10.0

ValidDateFromSelf (class)

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

Source

Since v3.10.0

Date filters

betweenDate

Signature

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

Source

Since v3.10.0

greaterThanDate

Signature

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

Source

Since v3.10.0

greaterThanOrEqualToDate

Signature

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

Source

Since v3.10.0

lessThanDate

Signature

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

Source

Since v3.10.0

lessThanOrEqualToDate

Signature

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

Source

Since v3.10.0

validDate

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 const validDate: <S extends Schema.Any>(
  annotations?: Annotations.Filter<Schema.Type<S>>
) => <A extends Date>(self: S & Schema<A, Schema.Encoded<S>, Schema.Context<S>>) => filter<S>

Source

Since v3.10.0

Date transformations

Date

This schema converts a string into a Date object using the new Date constructor. It ensures that only valid date strings are accepted, rejecting any strings that would result in an invalid date, such as new Date("Invalid Date").

Signature

declare const Date: typeof Date$

Source

Since v3.10.0

DateFromNumber (class)

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

Source

Since v3.10.0

DateFromString (class)

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

Source

Since v3.10.0

DateTime.Utc constructors

DateTimeUtcFromSelf (class)

Describes a schema that represents a DateTime.Utc instance.

Signature

declare class DateTimeUtcFromSelf

Source

Since v3.10.0

DateTime.Utc transformations

DateTimeUtc (class)

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

Signature

declare class DateTimeUtc

Source

Since v3.10.0

DateTimeUtcFromDate (class)

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

Signature

declare class DateTimeUtcFromDate

Source

Since v3.12.0

DateTimeUtcFromNumber (class)

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

Signature

declare class DateTimeUtcFromNumber

Source

Since v3.10.0

DateTime.Zoned constructors

DateTimeZonedFromSelf (class)

Describes a schema that represents a DateTime.Zoned instance.

Signature

declare class DateTimeZonedFromSelf

Source

Since v3.10.0

DateTime.Zoned transformations

DateTimeZoned (class)

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

Signature

declare class DateTimeZoned

Source

Since v3.10.0

Duration constructors

DurationFromSelf (class)

Signature

declare class DurationFromSelf

Source

Since v3.10.0

Duration filters

betweenDuration

Signature

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

Source

Since v3.10.0

greaterThanDuration

Signature

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

Source

Since v3.10.0

greaterThanOrEqualToDuration

Signature

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

Source

Since v3.10.0

lessThanDuration

Signature

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

Source

Since v3.10.0

lessThanOrEqualToDuration

Signature

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

Source

Since v3.10.0

Duration transformations

Duration (class)

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

Signature

declare class Duration

Source

Since v3.10.0

DurationFromMillis (class)

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

Source

Since v3.10.0

DurationFromNanos (class)

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

Signature

declare class DurationFromNanos

Source

Since v3.10.0

clampDuration

Clamps a Duration between a minimum and a maximum value.

Signature

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

Source

Since v3.10.0

Duration utils

DurationEncoded (type alias)

Signature

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

Source

Since v3.12.8

Either transformations

Either

Signature

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

Source

Since v3.10.0

EitherFromSelf

Signature

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

Source

Since v3.10.0

EitherFromUnion

Example

import * as Schema from "effect/Schema"

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

Signature

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

Source

Since v3.10.0

Either utils

EitherEncoded (type alias)

Signature

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

Source

Since v3.10.0

LeftEncoded (type alias)

Signature

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

Source

Since v3.10.0

RightEncoded (type alias)

Signature

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

Source

Since v3.10.0

Equivalence

equivalence

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

Signature

declare const equivalence: <A, I, R>(schema: Schema<A, I, R>) => Equivalence.Equivalence<A>

Source

Since v3.10.0

Exit transformations

Exit

Signature

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

Source

Since v3.10.0

ExitFromSelf

Signature

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

Source

Since v3.10.0

Exit utils

ExitEncoded (type alias)

Signature

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

Source

Since v3.10.0

FiberId

FiberIdEncoded (type alias)

Signature

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

Source

Since v3.10.0

FiberId constructors

FiberIdFromSelf (class)

Signature

declare class FiberIdFromSelf

Source

Since v3.10.0

FiberId transformations

FiberId (class)

Signature

declare class FiberId

Source

Since v3.10.0

HashMap transformations

HashMap

Signature

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

Source

Since v3.10.0

HashMapFromSelf

Signature

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

Source

Since v3.10.0

HashSet transformations

HashSet

Signature

declare const HashSet: <Value extends Schema.Any>(value: Value) => HashSet<Value>

Source

Since v3.10.0

HashSetFromSelf

Signature

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

Source

Since v3.10.0

List transformations

List

Signature

declare const List: <Value extends Schema.Any>(value: Value) => List<Value>

Source

Since v3.10.0

ListFromSelf

Signature

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

Source

Since v3.10.0

Map

MapFromSelf

Signature

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

Source

Since v3.10.0

Map transformations

Map

Signature

declare const Map: <K extends Schema.Any, V extends Schema.Any>({
  key,
  value
}: {
  readonly key: K
  readonly value: V
}) => Map$<K, V>

Source

Since v3.10.0

MapFromRecord

Signature

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

Source

Since v3.10.0

NonEmptyReadonlyArray transformations

headNonEmpty

Get the first element of a NonEmptyReadonlyArray.

Signature

declare const headNonEmpty: <S extends Schema.Any, A extends array_.NonEmptyReadonlyArray<unknown>>(
  self: S & Schema<A, Schema.Encoded<S>, Schema.Context<S>>
) => transform<S, SchemaClass<A[number]>>

Source

Since v3.12.0

Option transformations

Option

Signature

declare const Option: <Value extends Schema.Any>(value: Value) => Option<Value>

Source

Since v3.10.0

OptionFromNonEmptyTrimmedString (class)

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.

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 class OptionFromNonEmptyTrimmedString

Source

Since v3.10.0

OptionFromNullOr

Signature

declare const OptionFromNullOr: <Value extends Schema.Any>(value: Value) => OptionFromNullOr<Value>

Source

Since v3.10.0

OptionFromNullishOr

Signature

declare const OptionFromNullishOr: <Value extends Schema.Any>(
  value: Value,
  onNoneEncoding: null | undefined
) => OptionFromNullishOr<Value>

Source

Since v3.10.0

OptionFromSelf

Signature

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

Source

Since v3.10.0

OptionFromUndefinedOr

Signature

declare const OptionFromUndefinedOr: <Value extends Schema.Any>(value: Value) => OptionFromUndefinedOr<Value>

Source

Since v3.10.0

Option utils

OptionEncoded (type alias)

Signature

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

Source

Since v3.10.0

PropertySignature

FromPropertySignature (class)

Signature

declare class FromPropertySignature { constructor(
    type: AST.AST,
    isOptional: boolean,
    readonly isReadonly: boolean,
    annotations: AST.Annotations,
    readonly fromKey?: PropertyKey | undefined
  ) }

Source

Since v3.10.0

PropertySignature (interface)

Signature

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

  annotations(
    annotations: PropertySignature.Annotations<Type>
  ): PropertySignature<TypeToken, Type, Key, EncodedToken, Encoded, HasDefault, R>
}

Source

Since v3.10.0

PropertySignatureDeclaration (class)

Signature

declare class PropertySignatureDeclaration { constructor(
    type: AST.AST,
    isOptional: boolean,
    readonly isReadonly: boolean,
    annotations: AST.Annotations,
    readonly defaultValue: (() => unknown) | undefined
  ) }

Source

Since v3.10.0

toString (method)

Signature

declare const toString: () => string

Source

Since v3.10.0

_tag (property)

Signature

readonly _tag: "PropertySignatureDeclaration"

Source

Since v3.10.0

PropertySignatureTransformation (class)

Signature

declare class PropertySignatureTransformation { constructor(
    readonly from: FromPropertySignature,
    readonly to: ToPropertySignature,
    readonly decode: AST.PropertySignatureTransformation["decode"],
    readonly encode: AST.PropertySignatureTransformation["encode"]
  ) }

Source

Since v3.10.0

toString (method)

Signature

declare const toString: () => string

Source

Since v3.10.0

_tag (property)

Signature

readonly _tag: "PropertySignatureTransformation"

Source

Since v3.10.0

ToPropertySignature (class)

Signature

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

Source

Since v3.10.0

fromKey

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 PropertySignature.Token,
    Type,
    EncodedToken extends PropertySignature.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 PropertySignature.Token,
    Encoded,
    EncodedToken extends PropertySignature.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>
}

Source

Since v3.10.0

makePropertySignature

Signature

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

Source

Since v3.10.0

optional

Signature

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

Source

Since v3.10.0

optionalToOptional

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 const optionalToOptional: <FA, FI, FR, TA, TI, TR>(
  from: Schema<FA, FI, FR>,
  to: Schema<TA, TI, TR>,
  options: {
    readonly decode: (o: option_.Option<FA>) => option_.Option<TI>
    readonly encode: (o: option_.Option<TI>) => option_.Option<FA>
  }
) => PropertySignature<"?:", TA, never, "?:", FI, false, FR | TR>

Source

Since v3.10.0

optionalToRequired

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 const optionalToRequired: <FA, FI, FR, TA, TI, TR>(
  from: Schema<FA, FI, FR>,
  to: Schema<TA, TI, TR>,
  options: { readonly decode: (o: option_.Option<FA>) => TI; readonly encode: (ti: TI) => option_.Option<FA> }
) => PropertySignature<":", TA, never, "?:", FI, false, FR | TR>

Source

Since v3.10.0

optionalWith

Signature

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

Source

Since v3.10.0

propertySignature

Lifts a Schema into a PropertySignature.

Signature

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

Source

Since v3.10.0

requiredToOptional

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 const requiredToOptional: <FA, FI, FR, TA, TI, TR>(
  from: Schema<FA, FI, FR>,
  to: Schema<TA, TI, TR>,
  options: { readonly decode: (fa: FA) => option_.Option<TI>; readonly encode: (o: option_.Option<TI>) => FA }
) => PropertySignature<"?:", TA, never, ":", FI, false, FR | TR>

Source

Since v3.10.0

withConstructorDefault

Enhances a property signature with a default constructor value.

Signature

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

Source

Since v3.10.0

withDecodingDefault

Enhances a property signature with a default decoding value.

Signature

declare const withDecodingDefault: {
  <Type>(
    defaultValue: () => Types.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: () => Types.NoInfer<Exclude<Type, undefined>>
  ): PropertySignature<":", Exclude<Type, undefined>, Key, "?:", Encoded, false, R>
}

Source

Since v3.10.0

withDefaults

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>
}

Source

Since v3.10.0

ReadonlyArray filters

itemsCount

Signature

declare const itemsCount: <S extends Schema.Any>(
  n: number,
  annotations?: Annotations.Filter<Schema.Type<S>>
) => <A extends ReadonlyArray<any>>(self: S & Schema<A, Schema.Encoded<S>, Schema.Context<S>>) => filter<S>

Source

Since v3.10.0

maxItems

Signature

declare const maxItems: <S extends Schema.Any>(
  n: number,
  annotations?: Annotations.Filter<Schema.Type<S>>
) => <A extends ReadonlyArray<any>>(self: S & Schema<A, Schema.Encoded<S>, Schema.Context<S>>) => filter<S>

Source

Since v3.10.0

minItems

Signature

declare const minItems: <S extends Schema.Any>(
  n: number,
  annotations?: Annotations.Filter<Schema.Type<S>>
) => <A extends ReadonlyArray<any>>(self: S & Schema<A, Schema.Encoded<S>, Schema.Context<S>>) => filter<S>

Source

Since v3.10.0

ReadonlyArray transformations

getNumberIndexedAccess

Signature

declare const getNumberIndexedAccess: <A extends ReadonlyArray<any>, I extends ReadonlyArray<any>, R>(
  self: Schema<A, I, R>
) => SchemaClass<A[number], I[number], R>

Source

Since v3.10.0

Get the first element of a ReadonlyArray, or None if the array is empty.

Signature

declare const head: <S extends Schema.Any, A extends ReadonlyArray<unknown>>(
  self: S & Schema<A, Schema.Encoded<S>, Schema.Context<S>>
) => transform<S, OptionFromSelf<SchemaClass<A[number]>>>

Source

Since v3.10.0

headOrElse

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 Schema.Any, A extends ReadonlyArray<unknown>>(
    fallback?: LazyArg<A[number]>
  ): (self: S & Schema<A, Schema.Encoded<S>, Schema.Context<S>>) => transform<S, SchemaClass<A[number]>>
  <S extends Schema.Any, A extends ReadonlyArray<unknown>>(
    self: S & Schema<A, Schema.Encoded<S>, Schema.Context<S>>,
    fallback?: LazyArg<A[number]>
  ): transform<S, SchemaClass<A[number]>>
}

Source

Since v3.10.0

ReadonlyMap

ReadonlyMapFromSelf

Signature

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

Source

Since v3.10.0

ReadonlyMap transformations

ReadonlyMap

Signature

declare const ReadonlyMap: <K extends Schema.Any, V extends Schema.Any>({
  key,
  value
}: {
  readonly key: K
  readonly value: V
}) => ReadonlyMap$<K, V>

Source

Since v3.10.0

ReadonlyMapFromRecord

Signature

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

Source

Since v3.10.0

ReadonlySet

ReadonlySetFromSelf

Signature

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

Source

Since v3.10.0

ReadonlySet transformations

ReadonlySet

Signature

declare const ReadonlySet: <Value extends Schema.Any>(value: Value) => ReadonlySet$<Value>

Source

Since v3.10.0

Redacted constructors

RedactedFromSelf

Signature

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

Source

Since v3.10.0

Redacted transformations

Redacted

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

Signature

declare const Redacted: <Value extends Schema.Any>(value: Value) => Redacted<Value>

Source

Since v3.10.0

Set

SetFromSelf

Signature

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

Source

Since v3.10.0

Set transformations

Set

Signature

declare const Set: <Value extends Schema.Any>(value: Value) => Set$<Value>

Source

Since v3.10.0

SortedSet transformations

SortedSet

Signature

declare const SortedSet: <Value extends Schema.Any>(
  value: Value,
  ordA: Order.Order<Schema.Type<Value>>
) => SortedSet<Value>

Source

Since v3.10.0

SortedSetFromSelf

Signature

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

Source

Since v3.10.0

Standard Schema

standardSchemaV1

Returns a “Standard Schema” object conforming to the Standard Schema v1 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.

Example

import { Schema } from "effect"

const schema = Schema.Struct({
  name: Schema.String
})

//      ┌─── StandardSchemaV1<{ readonly name: string; }>
//      ▼
const standardSchema = Schema.standardSchemaV1(schema)

Signature

declare const standardSchemaV1: <A, I>(
  schema: Schema<A, I, never>,
  overrideOptions?: AST.ParseOptions
) => StandardSchemaV1<I, A> & SchemaClass<A, I, never>

Source

Since v3.13.0

TimeZone constructors

TimeZoneFromSelf (class)

Signature

declare class TimeZoneFromSelf

Source

Since v3.10.0

TimeZoneNamedFromSelf (class)

Describes a schema that represents a TimeZone.Named instance.

Signature

declare class TimeZoneNamedFromSelf

Source

Since v3.10.0

TimeZoneOffsetFromSelf (class)

Describes a schema that represents a TimeZone.Offset instance.

Signature

declare class TimeZoneOffsetFromSelf

Source

Since v3.10.0

TimeZone transformations

TimeZone (class)

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

Signature

declare class TimeZone

Source

Since v3.10.0

TimeZoneNamed (class)

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

Signature

declare class TimeZoneNamed

Source

Since v3.10.0

TimeZoneOffset (class)

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

Signature

declare class TimeZoneOffset

Source

Since v3.10.0

URL constructors

URLFromSelf (class)

Defines a schema that represents a URL object.

Signature

declare class URLFromSelf

Source

Since v3.11.0

URL transformations

URL

Defines a schema that attempts to convert a string to a URL object using the new URL constructor.

Signature

declare const URL: typeof URL$

Source

Since v3.11.0

Uint8Array constructors

Uint8ArrayFromSelf (class)

Signature

declare class Uint8ArrayFromSelf

Source

Since v3.10.0

Uint8Array transformations

Uint8Array

A schema that transforms an array of numbers into a Uint8Array.

Signature

declare const Uint8Array: typeof Uint8Array$

Source

Since v3.10.0

Uint8ArrayFromBase64

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

Signature

declare const Uint8ArrayFromBase64: Schema<Uint8Array<ArrayBufferLike>, string, never>

Source

Since v3.10.0

Uint8ArrayFromBase64Url

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

Signature

declare const Uint8ArrayFromBase64Url: Schema<Uint8Array<ArrayBufferLike>, string, never>

Source

Since v3.10.0

Uint8ArrayFromHex

Decodes a hex encoded string into a Uint8Array.

Signature

declare const Uint8ArrayFromHex: Schema<Uint8Array<ArrayBufferLike>, string, never>

Source

Since v3.10.0

accessor

exitSchema

Signature

declare const exitSchema: <SA, SI, FA, FI, R>(
  self: WithResult<SA, SI, FA, FI, R>
) => Schema<exit_.Exit<SA, FA>, ExitEncoded<SI, FI, unknown>, R>

Source

Since v3.10.0

failureSchema

Signature

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

Source

Since v3.10.0

serializableSchema

Signature

declare const serializableSchema: <A, I, R>(self: Serializable<A, I, R>) => Schema<A, I, R>

Source

Since v3.10.0

successSchema

Signature

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

Source

Since v3.10.0

annotations

Annotable (interface)

Signature

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

Source

Since v3.10.0

Annotable (namespace)

Source

Since v3.10.0

Self (type alias)

Signature

type Self<S> = ReturnType<S["annotations"]>

Source

Since v3.10.0

Any (type alias)

Signature

type Any = Annotable<any, any, any, unknown>

Source

Since v3.10.0

All (type alias)

Signature

type All =
  | Any
  | Annotable<any, any, never, unknown>
  | Annotable<any, never, any, unknown>
  | Annotable<any, never, never, unknown>

Source

Since v3.10.0

AnnotableClass (interface)

Signature

export interface AnnotableClass<Self extends Schema<A, I, R>, A, I = A, R = never> extends Annotable<Self, A, I, R> {
  new (_: never): Schema.Variance<A, I, R>
}

Source

Since v3.10.0

Annotations (namespace)

Source

Since v3.10.0

Doc (interface)

Signature

export interface Doc<A> extends AST.Annotations {
  readonly title?: AST.TitleAnnotation
  readonly description?: AST.DescriptionAnnotation
  readonly documentation?: AST.DocumentationAnnotation
  readonly examples?: AST.ExamplesAnnotation<A>
  readonly default?: AST.DefaultAnnotation<A>
}

Source

Since v3.10.0

Schema (interface)

Signature

export interface Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []> extends Doc<A> {
  readonly identifier?: AST.IdentifierAnnotation
  readonly message?: AST.MessageAnnotation
  readonly schemaId?: AST.SchemaIdAnnotation
  readonly jsonSchema?: AST.JSONSchemaAnnotation
  readonly arbitrary?: ArbitraryAnnotation<A, TypeParameters>
  readonly pretty?: pretty_.PrettyAnnotation<A, TypeParameters>
  readonly equivalence?: AST.EquivalenceAnnotation<A, TypeParameters>
  readonly concurrency?: AST.ConcurrencyAnnotation
  readonly batching?: AST.BatchingAnnotation
  readonly parseIssueTitle?: AST.ParseIssueTitleAnnotation
  readonly parseOptions?: AST.ParseOptions
  readonly decodingFallback?: AST.DecodingFallbackAnnotation<A>
}

Source

Since v3.10.0

GenericSchema (interface)

Signature

export interface GenericSchema<A> extends Schema<A> {
  readonly arbitrary?: (..._: any) => LazyArbitrary<A>
  readonly pretty?: (..._: any) => pretty_.Pretty<A>
  readonly equivalence?: (..._: any) => Equivalence.Equivalence<A>
}

Source

Since v3.11.6

Filter (interface)

Signature

export interface Filter<A, P = A> extends Schema<A, readonly [P]> {}

Source

Since v3.10.0

annotations

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

Signature

declare const annotations: {
  <S extends Annotable.All>(annotations: Annotations.GenericSchema<Schema.Type<S>>): (self: S) => Annotable.Self<S>
  <S extends Annotable.All>(self: S, annotations: Annotations.GenericSchema<Schema.Type<S>>): Annotable.Self<S>
}

Source

Since v3.10.0

api interface

AnnotableDeclare (interface)

Signature

export 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> {
  annotations(annotations: Annotations.Schema<A>): Self
}

Source

Since v3.13.3

Array$ (interface)

Signature

export interface Array$<Value extends Schema.Any> extends TupleType<[], [Value]> {
  readonly value: Value
  annotations(annotations: Annotations.Schema<TupleType.Type<[], [Value]>>): Array$<Value>
}

Source

Since v3.10.0

ArrayEnsure (interface)

Signature

export interface ArrayEnsure<Value extends Schema.Any>
  extends transform<Union<[Value, Array$<Value>]>, Array$<SchemaClass<Schema.Type<Value>>>> {}

Source

Since v3.10.0

Cause (interface)

Signature

export 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>>>
  > {}

Source

Since v3.10.0

CauseFromSelf (interface)

Signature

export 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]
  > {}

Source

Since v3.10.0

Chunk (interface)

Signature

export interface Chunk<Value extends Schema.Any>
  extends transform<Array$<Value>, ChunkFromSelf<SchemaClass<Schema.Type<Value>>>> {}

Source

Since v3.10.0

ChunkFromSelf (interface)

Signature

export interface ChunkFromSelf<Value extends Schema.Any>
  extends AnnotableDeclare<
    ChunkFromSelf<Value>,
    chunk_.Chunk<Schema.Type<Value>>,
    chunk_.Chunk<Schema.Encoded<Value>>,
    [Value]
  > {}

Source

Since v3.10.0

Class (interface)

Signature

export interface Class<Self, Fields extends Struct.Fields, I, R, C, Inherited, Proto>
  extends Schema<Self, Simplify<I>, R> {
  new (
    props: RequiredKeys<C> extends never ? void | Simplify<C> : Simplify<C>,
    options?: MakeOptions
  ): Struct.Type<Fields> & Inherited & Proto

  /** @since 3.10.0 */
  readonly ast: AST.Transformation

  make(props: RequiredKeys<C> extends never ? void | Simplify<C> : Simplify<C>, options?: MakeOptions): Self

  annotations(annotations: Annotations.Schema<Self>): SchemaClass<Self, Simplify<I>, R>

  readonly fields: { readonly [K in keyof Fields]: Fields[K] }

  readonly identifier: string

  /**
   * @example
   * ```ts
   * import { Schema } from "effect"
   *
   * class MyClass extends Schema.Class<MyClass>("MyClass")({
   *  myField: Schema.String
   * }) {
   *  myMethod() {
   *    return this.myField + "my"
   *  }
   * }
   *
   * class NextClass extends MyClass.extend<NextClass>("NextClass")({
   *  nextField: Schema.Number
   * }) {
   *  nextMethod() {
   *    return this.myMethod() + this.myField + this.nextField
   *  }
   * }
   * ```
   */
  extend<Extended = never>(
    identifier: string
  ): <NewFields extends Struct.Fields>(
    fields: NewFields | HasFields<NewFields>,
    annotations?: ClassAnnotations<Extended, Simplify<Struct.Type<Fields & NewFields>>>
  ) => [Extended] extends [never]
    ? MissingSelfGeneric<"Base.extend">
    : Class<
        Extended,
        Fields & NewFields,
        I & Struct.Encoded<NewFields>,
        R | Struct.Context<NewFields>,
        C & Struct.Constructor<NewFields>,
        Self,
        Proto
      >

  /**
   * @example
   * ```ts
   * import { Effect, Schema } from "effect"
   *
   * class MyClass extends Schema.Class<MyClass>("MyClass")({
   *   myField: Schema.String
   * }) {
   *   myMethod() {
   *     return this.myField + "my"
   *   }
   * }
   *
   * class NextClass extends MyClass.transformOrFail<NextClass>("NextClass")({
   *   nextField: Schema.Number
   * }, {
   *   decode: (i) =>
   *     Effect.succeed({
   *       myField: i.myField,
   *       nextField: i.myField.length
   *     }),
   *   encode: (a) => Effect.succeed({ myField: a.myField })
   * }) {
   *   nextMethod() {
   *     return this.myMethod() + this.myField + this.nextField
   *   }
   * }
   * ```
   */
  transformOrFail<Transformed = never>(
    identifier: string
  ): <NewFields extends Struct.Fields, R2, R3>(
    fields: NewFields,
    options: {
      readonly decode: (
        input: Simplify<Struct.Type<Fields>>,
        options: ParseOptions,
        ast: AST.Transformation
      ) => Effect.Effect<Simplify<Struct.Type<Fields & NewFields>>, ParseResult.ParseIssue, R2>
      readonly encode: (
        input: Simplify<Struct.Type<Fields & NewFields>>,
        options: ParseOptions,
        ast: AST.Transformation
      ) => Effect.Effect<Struct.Type<Fields>, ParseResult.ParseIssue, R3>
    },
    annotations?: ClassAnnotations<Transformed, Simplify<Struct.Type<Fields & NewFields>>>
  ) => [Transformed] extends [never]
    ? MissingSelfGeneric<"Base.transformOrFail">
    : Class<
        Transformed,
        Fields & NewFields,
        I,
        R | Struct.Context<NewFields> | R2 | R3,
        C & Struct.Constructor<NewFields>,
        Self,
        Proto
      >

  /**
   * @example
   * ```ts
   * import { Effect, Schema } from "effect"
   *
   * class MyClass extends Schema.Class<MyClass>("MyClass")({
   *   myField: Schema.String
   * }) {
   *   myMethod() {
   *     return this.myField + "my"
   *   }
   * }
   *
   * class NextClass extends MyClass.transformOrFailFrom<NextClass>("NextClass")({
   *   nextField: Schema.Number
   * }, {
   *   decode: (i) =>
   *     Effect.succeed({
   *       myField: i.myField,
   *       nextField: i.myField.length
   *     }),
   *   encode: (a) => Effect.succeed({ myField: a.myField })
   * }) {
   *   nextMethod() {
   *     return this.myMethod() + this.myField + this.nextField
   *   }
   * }
   * ```
   */
  transformOrFailFrom<Transformed = never>(
    identifier: string
  ): <NewFields extends Struct.Fields, R2, R3>(
    fields: NewFields,
    options: {
      readonly decode: (
        input: Simplify<I>,
        options: ParseOptions,
        ast: AST.Transformation
      ) => Effect.Effect<Simplify<I & Struct.Encoded<NewFields>>, ParseResult.ParseIssue, R2>
      readonly encode: (
        input: Simplify<I & Struct.Encoded<NewFields>>,
        options: ParseOptions,
        ast: AST.Transformation
      ) => Effect.Effect<I, ParseResult.ParseIssue, R3>
    },
    annotations?: ClassAnnotations<Transformed, Simplify<Struct.Type<Fields & NewFields>>>
  ) => [Transformed] extends [never]
    ? MissingSelfGeneric<"Base.transformOrFailFrom">
    : Class<
        Transformed,
        Fields & NewFields,
        I,
        R | Struct.Context<NewFields> | R2 | R3,
        C & Struct.Constructor<NewFields>,
        Self,
        Proto
      >
}

Source

Since v3.10.0

Data (interface)

Signature

export interface Data<Value extends Schema.Any>
  extends transform<Value, DataFromSelf<SchemaClass<Schema.Type<Value>>>> {}

Source

Since v3.13.3

DataFromSelf (interface)

Signature

export interface DataFromSelf<Value extends Schema.Any>
  extends AnnotableDeclare<DataFromSelf<Value>, Schema.Type<Value>, Schema.Encoded<Value>, [Value]> {}

Source

Since v3.13.3

Either (interface)

Signature

export 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>>>
  > {}

Source

Since v3.10.0

EitherFromSelf (interface)

Signature

export 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]
  > {}

Source

Since v3.10.0

EitherFromUnion (interface)

Signature

export 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>>>
  > {}

Source

Since v3.10.0

Enums (interface)

Signature

export interface Enums<A extends EnumsDefinition> extends AnnotableClass<Enums<A>, A[keyof A]> {
  readonly enums: A
}

Source

Since v3.10.0

Exit (interface)

Signature

export 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>>>
  > {}

Source

Since v3.10.0

ExitFromSelf (interface)

Signature

export 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]
  > {}

Source

Since v3.10.0

HashMap (interface)

Signature

export 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>>>> {}

Source

Since v3.10.0

HashMapFromSelf (interface)

Signature

export 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]
  > {}

Source

Since v3.10.0

HashSet (interface)

Signature

export interface HashSet<Value extends Schema.Any>
  extends transform<Array$<Value>, HashSetFromSelf<SchemaClass<Schema.Type<Value>>>> {}

Source

Since v3.10.0

HashSetFromSelf (interface)

Signature

export interface HashSetFromSelf<Value extends Schema.Any>
  extends AnnotableDeclare<
    HashSetFromSelf<Value>,
    hashSet_.HashSet<Schema.Type<Value>>,
    hashSet_.HashSet<Schema.Encoded<Value>>,
    [Value]
  > {}

Source

Since v3.10.0

List (interface)

Signature

export interface List<Value extends Schema.Any>
  extends transform<Array$<Value>, ListFromSelf<SchemaClass<Schema.Type<Value>>>> {}

Source

Since v3.10.0

ListFromSelf (interface)

Signature

export interface ListFromSelf<Value extends Schema.Any>
  extends AnnotableDeclare<
    ListFromSelf<Value>,
    list_.List<Schema.Type<Value>>,
    list_.List<Schema.Encoded<Value>>,
    [Value]
  > {}

Source

Since v3.10.0

Literal (interface)

Signature

export interface Literal<Literals extends array_.NonEmptyReadonlyArray<AST.LiteralValue>>
  extends AnnotableClass<Literal<Literals>, Literals[number]> {
  readonly literals: Readonly<Literals>
}

Source

Since v3.10.0

Map$ (interface)

Signature

export 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>>>> {}

Source

Since v3.10.0

MapFromSelf (interface)

Signature

export 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]
  > {}

Source

Since v3.10.0

NonEmptyArray (interface)

Signature

export interface NonEmptyArray<Value extends Schema.Any>
  extends AnnotableClass<
    NonEmptyArray<Value>,
    array_.NonEmptyReadonlyArray<Schema.Type<Value>>,
    array_.NonEmptyReadonlyArray<Schema.Encoded<Value>>,
    Schema.Context<Value>
  > {
  readonly elements: readonly [Value]
  readonly rest: readonly [Value]
  readonly value: Value
}

Source

Since v3.10.0

NonEmptyArrayEnsure (interface)

Signature

export interface NonEmptyArrayEnsure<Value extends Schema.Any>
  extends transform<Union<[Value, NonEmptyArray<Value>]>, NonEmptyArray<SchemaClass<Schema.Type<Value>>>> {}

Source

Since v3.10.0

NonEmptyChunk (interface)

Signature

export interface NonEmptyChunk<Value extends Schema.Any>
  extends transform<NonEmptyArray<Value>, NonEmptyChunkFromSelf<SchemaClass<Schema.Type<Value>>>> {}

Source

Since v3.10.0

NonEmptyChunkFromSelf (interface)

Signature

export interface NonEmptyChunkFromSelf<Value extends Schema.Any>
  extends AnnotableDeclare<
    NonEmptyChunkFromSelf<Value>,
    chunk_.NonEmptyChunk<Schema.Type<Value>>,
    chunk_.NonEmptyChunk<Schema.Encoded<Value>>,
    [Value]
  > {}

Source

Since v3.10.0

NullOr (interface)

Signature

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

Source

Since v3.10.0

NullishOr (interface)

Signature

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

Source

Since v3.10.0

Option (interface)

Signature

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

Source

Since v3.10.0

OptionFromNullOr (interface)

Signature

export interface OptionFromNullOr<Value extends Schema.Any>
  extends transform<NullOr<Value>, OptionFromSelf<SchemaClass<Schema.Type<Value>>>> {}

Source

Since v3.10.0

OptionFromNullishOr (interface)

Signature

export interface OptionFromNullishOr<Value extends Schema.Any>
  extends transform<NullishOr<Value>, OptionFromSelf<SchemaClass<Schema.Type<Value>>>> {}

Source

Since v3.10.0

OptionFromSelf (interface)

Signature

export interface OptionFromSelf<Value extends Schema.Any>
  extends AnnotableDeclare<
    OptionFromSelf<Value>,
    option_.Option<Schema.Type<Value>>,
    option_.Option<Schema.Encoded<Value>>,
    [Value]
  > {}

Source

Since v3.10.0

OptionFromUndefinedOr (interface)

Signature

export interface OptionFromUndefinedOr<Value extends Schema.Any>
  extends transform<UndefinedOr<Value>, OptionFromSelf<SchemaClass<Schema.Type<Value>>>> {}

Source

Since v3.10.0

ReadonlyMap$ (interface)

Signature

export 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>>>
  > {}

Source

Since v3.10.0

ReadonlyMapFromSelf (interface)

Signature

export 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]
  > {}

Source

Since v3.10.0

ReadonlySet$ (interface)

Signature

export interface ReadonlySet$<Value extends Schema.Any>
  extends transform<Array$<Value>, ReadonlySetFromSelf<SchemaClass<Schema.Type<Value>>>> {}

Source

Since v3.10.0

ReadonlySetFromSelf (interface)

Signature

export interface ReadonlySetFromSelf<Value extends Schema.Any>
  extends AnnotableDeclare<
    ReadonlySetFromSelf<Value>,
    ReadonlySet<Schema.Type<Value>>,
    ReadonlySet<Schema.Encoded<Value>>,
    [Value]
  > {}

Source

Since v3.10.0

Record$ (interface)

Signature

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

Source

Since v3.10.0

Redacted (interface)

Signature

export interface Redacted<Value extends Schema.Any>
  extends transform<Value, RedactedFromSelf<SchemaClass<Schema.Type<Value>>>> {}

Source

Since v3.10.0

RedactedFromSelf (interface)

Signature

export interface RedactedFromSelf<Value extends Schema.Any>
  extends AnnotableDeclare<
    RedactedFromSelf<Value>,
    redacted_.Redacted<Schema.Type<Value>>,
    redacted_.Redacted<Schema.Encoded<Value>>,
    [Value]
  > {}

Source

Since v3.10.0

Set$ (interface)

Signature

export interface Set$<Value extends Schema.Any>
  extends transform<Array$<Value>, SetFromSelf<SchemaClass<Schema.Type<Value>>>> {}

Source

Since v3.10.0

SetFromSelf (interface)

Signature

export interface SetFromSelf<Value extends Schema.Any>
  extends AnnotableDeclare<SetFromSelf<Value>, Set<Schema.Type<Value>>, ReadonlySet<Schema.Encoded<Value>>, [Value]> {}

Source

Since v3.10.0

SortedSet (interface)

Signature

export interface SortedSet<Value extends Schema.Any>
  extends transform<Array$<Value>, SortedSetFromSelf<SchemaClass<Schema.Type<Value>>>> {}

Source

Since v3.10.0

SortedSetFromSelf (interface)

Signature

export interface SortedSetFromSelf<Value extends Schema.Any>
  extends AnnotableDeclare<
    SortedSetFromSelf<Value>,
    sortedSet_.SortedSet<Schema.Type<Value>>,
    sortedSet_.SortedSet<Schema.Encoded<Value>>,
    [Value]
  > {}

Source

Since v3.10.0

Struct (interface)

Signature

export interface Struct<Fields extends Struct.Fields>
  extends AnnotableClass<
    Struct<Fields>,
    Simplify<Struct.Type<Fields>>,
    Simplify<Struct.Encoded<Fields>>,
    Struct.Context<Fields>
  > {
  readonly fields: Readonly<Fields>
  readonly records: readonly []
  make(
    props: RequiredKeys<Struct.Constructor<Fields>> extends never
      ? void | Simplify<Struct.Constructor<Fields>>
      : Simplify<Struct.Constructor<Fields>>,
    options?: MakeOptions
  ): Simplify<Struct.Type<Fields>>

  annotations(annotations: Annotations.Schema<Simplify<Struct.Type<Fields>>>): Struct<Fields>
  pick<Keys extends ReadonlyArray<keyof Fields>>(...keys: Keys): Struct<Simplify<Pick<Fields, Keys[number]>>>
  omit<Keys extends ReadonlyArray<keyof Fields>>(...keys: Keys): Struct<Simplify<Omit<Fields, Keys[number]>>>
}

Source

Since v3.10.0

TaggedClass (interface)

Signature

export 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">>,
    {},
    {}
  > {
  readonly _tag: Tag
}

Source

Since v3.10.0

TaggedErrorClass (interface)

Signature

export 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
  > {
  readonly _tag: Tag
}

Source

Since v3.10.0

TaggedRequestClass (interface)

Signature

export 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>
    >,
    {}
  > {
  readonly _tag: Tag
  readonly success: Success
  readonly failure: Failure
}

Source

Since v3.10.0

TaggedStruct (type alias)

Signature

type TaggedStruct<Tag, Fields> = Struct<{ _tag: tag<Tag> } & Fields>

Source

Since v3.10.0

Tuple (interface)

Signature

export interface Tuple<Elements extends TupleType.Elements> extends TupleType<Elements, []> {
  annotations(annotations: Annotations.Schema<TupleType.Type<Elements, []>>): Tuple<Elements>
}

Source

Since v3.10.0

Tuple2 (interface)

Signature

export 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>
  > {
  readonly elements: readonly [Fst, Snd]
  readonly rest: readonly []
}

Source

Since v3.13.3

TupleType (interface)

Signature

export 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]>
  > {
  readonly elements: Readonly<Elements>
  readonly rest: Readonly<Rest>
}

Source

Since v3.10.0

TypeLiteral (interface)

Signature

export 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>
  > {
  readonly fields: Readonly<Fields>
  readonly records: Readonly<Records>
  annotations(
    annotations: Annotations.Schema<Simplify<TypeLiteral.Type<Fields, Records>>>
  ): TypeLiteral<Fields, Records>
  make(
    props: RequiredKeys<TypeLiteral.Constructor<Fields, Records>> extends never
      ? void | Simplify<TypeLiteral.Constructor<Fields, Records>>
      : Simplify<TypeLiteral.Constructor<Fields, Records>>,
    options?: MakeOptions
  ): Simplify<TypeLiteral.Type<Fields, Records>>
}

Source

Since v3.10.0

UndefinedOr (interface)

Signature

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

Source

Since v3.10.0

Union (interface)

Signature

export interface Union<Members extends ReadonlyArray<Schema.All>>
  extends AnnotableClass<
    Union<Members>,
    Schema.Type<Members[number]>,
    Schema.Encoded<Members[number]>,
    Schema.Context<Members[number]>
  > {
  readonly members: Readonly<Members>
}

Source

Since v3.10.0

brand (interface)

Signature

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

Source

Since v3.10.0

declare (interface)

Signature

export 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> {
  readonly typeParameters: Readonly<P>
}

Source

Since v3.13.3

extend (interface)

Signature

export 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>
  > {}

Source

Since v3.10.0

filter (interface)

Signature

export interface filter<From extends Schema.Any> extends refine<Schema.Type<From>, From> {}

Source

Since v3.10.0

filterEffect (interface)

Signature

export interface filterEffect<S extends Schema.Any, FD = never>
  extends transformOrFail<S, SchemaClass<Schema.Type<S>>, FD> {}

Source

Since v3.10.0

instanceOf (interface)

Signature

export interface instanceOf<A> extends AnnotableDeclare<instanceOf<A>, A> {}

Source

Since v3.10.0

mutable (interface)

Signature

export interface mutable<S extends Schema.Any>
  extends AnnotableClass<
    mutable<S>,
    SimplifyMutable<Schema.Type<S>>,
    SimplifyMutable<Schema.Encoded<S>>,
    Schema.Context<S>
  > {}

Source

Since v3.10.0

optional (interface)

Signature

export 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: PropertySignature.Annotations<Schema.Type<S> | undefined>): optional<S>
}

Source

Since v3.10.0

optionalWith (interface)

Signature

export 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: PropertySignature.Annotations<
      | (Types.Has<Options, "as"> extends true ? option_.Option<Schema.Type<S>> : Schema.Type<S>)
      | (Types.Has<Options, "as" | "default" | "exact"> extends true ? never : undefined)
    >
  ): optionalWith<S, Options>
}

Source

Since v3.10.0

refine (interface)

Signature

export interface refine<A, From extends Schema.Any>
  extends AnnotableClass<refine<A, From>, A, Schema.Encoded<From>, Schema.Context<From>> {
  /** The following is required for {@link HasFields} to work */
  readonly [RefineSchemaId]: From
  readonly from: From
  readonly filter: (
    a: Schema.Type<From>,
    options: ParseOptions,
    self: AST.Refinement
  ) => option_.Option<ParseResult.ParseIssue>
  make(a: Schema.Type<From>, options?: MakeOptions): A
}

Source

Since v3.10.0

suspend (interface)

Signature

export interface suspend<A, I, R> extends AnnotableClass<suspend<A, I, R>, A, I, R> {}

Source

Since v3.10.0

tag (interface)

Signature

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

Source

Since v3.10.0

transform (interface)

Signature

export interface transform<From extends Schema.All, To extends Schema.All> extends transformOrFail<From, To> {
  annotations(annotations: Annotations.Schema<Schema.Type<To>>): transform<From, To>
}

Source

Since v3.10.0

transformLiteral (interface)

Signature

export interface transformLiteral<Type extends AST.LiteralValue, Encoded extends AST.LiteralValue>
  extends transform<Literal<[Encoded]>, Literal<[Type]>> {
  annotations(annotations: Annotations.Schema<Type>): transformLiteral<Type, Encoded>
}

Source

Since v3.10.0

transformOrFail (interface)

Signature

export 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
  > {
  readonly from: From
  readonly to: To
}

Source

Since v3.10.0

bigint constructors

NegativeBigInt

Signature

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

Source

Since v3.10.0

NegativeBigIntFromSelf

Signature

declare const NegativeBigIntFromSelf: filter<Schema<bigint, bigint, never>>

Source

Since v3.10.0

NonNegativeBigInt

Signature

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

Source

Since v3.10.0

NonNegativeBigIntFromSelf

Signature

declare const NonNegativeBigIntFromSelf: filter<Schema<bigint, bigint, never>>

Source

Since v3.10.0

NonPositiveBigInt

Signature

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

Source

Since v3.10.0

NonPositiveBigIntFromSelf

Signature

declare const NonPositiveBigIntFromSelf: filter<Schema<bigint, bigint, never>>

Source

Since v3.10.0

PositiveBigInt

Signature

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

Source

Since v3.10.0

PositiveBigIntFromSelf

Signature

declare const PositiveBigIntFromSelf: filter<Schema<bigint, bigint, never>>

Source

Since v3.10.0

bigint filters

betweenBigInt

Signature

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

Source

Since v3.10.0

greaterThanBigInt

Signature

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

Source

Since v3.10.0

greaterThanOrEqualToBigInt

Signature

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

Source

Since v3.10.0

lessThanBigInt

Signature

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

Source

Since v3.10.0

lessThanOrEqualToBigInt

Signature

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

Source

Since v3.10.0

negativeBigInt

Signature

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

Source

Since v3.10.0

nonNegativeBigInt

Signature

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

Source

Since v3.10.0

nonPositiveBigInt

Signature

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

Source

Since v3.10.0

positiveBigInt

Signature

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

Source

Since v3.10.0

bigint transformations

BigInt

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

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

Signature

declare const BigInt: typeof BigInt$

Source

Since v3.10.0

BigIntFromNumber (class)

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

Source

Since v3.10.0

clampBigInt

Clamps a bigint between a minimum and a maximum value.

Signature

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

Source

Since v3.10.0

boolean constructors

BooleanFromUnknown (class)

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

Source

Since v3.10.0

boolean transformations

BooleanFromString (class)

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

Signature

declare class BooleanFromString

Source

Since v3.11.0

Not (class)

Signature

declare class Not

Source

Since v3.10.0

branding

BrandSchema (interface)

Signature

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

Source

Since v3.10.0

brand

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

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">

Signature

declare const brand: <S extends Schema.AnyNoContext, B extends string | symbol>(
  brand: B,
  annotations?: Annotations.Schema<Schema.Type<S> & Brand<B>>
) => (self: S) => brand<S, B>

Source

Since v3.10.0

classes

Class

Example

import { Schema } from "effect"

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

Signature

declare const Class: <Self = never>(
  identifier: string
) => <Fields extends Struct.Fields>(
  fieldsOr: Fields | HasFields<Fields>,
  annotations?: ClassAnnotations<Self, Simplify<Struct.Type<Fields>>>
) => [Self] extends [never]
  ? MissingSelfGeneric<"Class">
  : Class<Self, Fields, Struct.Encoded<Fields>, Struct.Context<Fields>, Struct.Constructor<Fields>, {}, {}>

Source

Since v3.10.0

TaggedClass

Example

import { Schema } from "effect"

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

Signature

declare const TaggedClass: <Self = never>(
  identifier?: string
) => <Tag extends string, Fields extends Struct.Fields>(
  tag: Tag,
  fieldsOr: Fields | HasFields<Fields>,
  annotations?: ClassAnnotations<Self, Simplify<Struct.Type<{ readonly _tag: tag<Tag> } & Fields>>>
) => [Self] extends [never]
  ? MissingSelfGeneric<"TaggedClass", `"Tag", `>
  : TaggedClass<Self, Tag, { readonly _tag: tag<Tag> } & Fields>

Source

Since v3.10.0

TaggedError

Example

import { Schema } from "effect"

class MyError extends Schema.TaggedError<MyError>("MyError")("MyError", {
  module: Schema.String,
  method: Schema.String,
  description: Schema.String
}) {
  get message(): string {
    return `${this.module}.${this.method}: ${this.description}`
  }
}

Signature

declare const TaggedError: <Self = never>(
  identifier?: string
) => <Tag extends string, Fields extends Struct.Fields>(
  tag: Tag,
  fieldsOr: Fields | HasFields<Fields>,
  annotations?: ClassAnnotations<Self, Simplify<Struct.Type<{ readonly _tag: tag<Tag> } & Fields>>>
) => [Self] extends [never]
  ? MissingSelfGeneric<"TaggedError", `"Tag", `>
  : TaggedErrorClass<Self, Tag, { readonly _tag: tag<Tag> } & Fields>

Source

Since v3.10.0

TaggedRequest

Example

import { Schema } from "effect"

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

Signature

declare const TaggedRequest: <Self = never>(
  identifier?: string
) => <Tag extends string, Payload extends Struct.Fields, Success extends Schema.All, Failure extends Schema.All>(
  tag: Tag,
  options: { failure: Failure; success: Success; payload: Payload },
  annotations?: ClassAnnotations<Self, Simplify<Struct.Type<{ readonly _tag: tag<Tag> } & Payload>>>
) => [Self] extends [never]
  ? MissingSelfGeneric<"TaggedRequest", `"Tag", SuccessSchema, FailureSchema, `>
  : TaggedRequestClass<Self, Tag, { readonly _tag: tag<Tag> } & Payload, Success, Failure>

Source

Since v3.10.0

combinators

NullOr

Signature

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

Source

Since v3.10.0

NullishOr

Signature

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

Source

Since v3.10.0

UndefinedOr

Signature

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

Source

Since v3.10.0

Union

Signature

declare const Union: {
  <Members extends AST.Members<Schema.All>>(...members: Members): Union<Members>
  <Member extends Schema.All>(member: Member): Member
  (): typeof Never
  <Members extends ReadonlyArray<Schema.All>>(
    ...members: Members
  ): Schema<Schema.Type<Members[number]>, Schema.Encoded<Members[number]>, Schema.Context<Members[number]>>
}

Source

Since v3.10.0

attachPropertySignature

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.

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
})

Signature

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

Source

Since v3.10.0

compose

Signature

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

Source

Since v3.10.0

extend

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

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
  )
)

Signature

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

Source

Since v3.10.0

keyof

Signature

declare const keyof: <A, I, R>(self: Schema<A, I, R>) => SchemaClass<keyof A>

Source

Since v3.10.0

mutable

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

Signature

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

Source

Since v3.10.0

partial

Signature

declare const partial: <A, I, R>(
  self: Schema<A, I, R>
) => SchemaClass<{ [K in keyof A]?: A[K] | undefined }, { [K in keyof I]?: I[K] | undefined }, R>

Source

Since v3.10.0

partialWith

Signature

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

Source

Since v3.10.0

required

Signature

declare const required: <A, I, R>(
  self: Schema<A, I, R>
) => SchemaClass<{ [K in keyof A]-?: A[K] }, { [K in keyof I]-?: I[K] }, R>

Source

Since v3.10.0

constructors

Array

Signature

declare const Array: <Value extends Schema.Any>(value: Value) => Array$<Value>

Source

Since v3.10.0

ArrayEnsure

Signature

declare const ArrayEnsure: <Value extends Schema.Any>(value: Value) => ArrayEnsure<Value>

Source

Since v3.10.0

Enums

Signature

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

Source

Since v3.10.0

Literal

Signature

declare const Literal: {
  <Literals extends array_.NonEmptyReadonlyArray<AST.LiteralValue>>(...literals: Literals): Literal<Literals>
  (): Never
  <Literals extends ReadonlyArray<AST.LiteralValue>>(...literals: Literals): SchemaClass<Literals[number]>
}

Source

Since v3.10.0

NonEmptyArray

Signature

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

Source

Since v3.10.0

NonEmptyArrayEnsure

Signature

declare const NonEmptyArrayEnsure: <Value extends Schema.Any>(value: Value) => NonEmptyArrayEnsure<Value>

Source

Since v3.10.0

Record

Signature

declare const Record: <K extends Schema.All, V extends Schema.All>(options: {
  readonly key: K
  readonly value: V
}) => Record$<K, V>

Source

Since v3.10.0

Struct

Signature

declare const Struct: {
  <Fields extends Struct.Fields, const Records extends IndexSignature.NonEmptyRecords>(
    fields: Fields,
    ...records: Records
  ): TypeLiteral<Fields, Records>
  <Fields extends Struct.Fields>(fields: Fields): Struct<Fields>
}

Source

Since v3.10.0

TaggedStruct

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.

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 })

Signature

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

Source

Since v3.10.0

Tuple

Signature

declare const Tuple: {
  <const Elements extends TupleType.Elements, Rest extends array_.NonEmptyReadonlyArray<TupleType.Rest[number]>>(
    elements: Elements,
    ...rest: Rest
  ): TupleType<Elements, Rest>
  <Fst extends Schema.Any, Snd extends Schema.Any>(fst: Fst, snd: Snd): Tuple2<Fst, Snd>
  <Elements extends TupleType.Elements>(...elements: Elements): Tuple<Elements>
}

Source

Since v3.10.0

UniqueSymbolFromSelf

Signature

declare const UniqueSymbolFromSelf: <S extends symbol>(symbol: S) => SchemaClass<S>

Source

Since v3.10.0

declare

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?: Annotations.Schema<A>): declare<A>
  <A, I, const P extends ReadonlyArray<Schema.All>>(
    typeParameters: P,
    options: {
      readonly decode: (
        ...typeParameters: { readonly [K in keyof P]: Schema<Schema.Type<P[K]>, Schema.Encoded<P[K]>, never> }
      ) => (
        input: unknown,
        options: ParseOptions,
        ast: AST.Declaration
      ) => Effect.Effect<A, ParseResult.ParseIssue, never>
      readonly encode: (
        ...typeParameters: { readonly [K in keyof P]: Schema<Schema.Type<P[K]>, Schema.Encoded<P[K]>, never> }
      ) => (
        input: unknown,
        options: ParseOptions,
        ast: AST.Declaration
      ) => Effect.Effect<I, ParseResult.ParseIssue, never>
    },
    annotations?: Annotations.Schema<A, { readonly [K in keyof P]: Schema.Type<P[K]> }>
  ): declare<A, I, P>
}

Source

Since v3.10.0

fromBrand

Signature

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

Source

Since v3.10.0

instanceOf

Signature

declare const instanceOf: <A extends abstract new (...args: any) => any>(
  constructor: A,
  annotations?: Annotations.Schema<InstanceType<A>>
) => instanceOf<InstanceType<A>>

Source

Since v3.10.0

make

Signature

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

Source

Since v3.10.0

pickLiteral

Creates a new Schema from a literal schema.

Example

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

const schema = Schema.Literal("a", "b", "c").pipe(Schema.pickLiteral("a", "b"))

assert.deepStrictEqual(Schema.decodeSync(schema)("a"), "a")
assert.deepStrictEqual(Schema.decodeSync(schema)("b"), "b")
assert.strictEqual(Either.isLeft(Schema.decodeUnknownEither(schema)("c")), true)

Signature

declare const pickLiteral: <A extends AST.LiteralValue, L extends array_.NonEmptyReadonlyArray<A>>(
  ...literals: L
) => <I, R>(_schema: Schema<A, I, R>) => Literal<[...L]>

Source

Since v3.10.0

suspend

Signature

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

Source

Since v3.10.0

transformLiteral

Creates a new Schema which transforms literal values.

Example

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

const schema = S.transformLiteral(0, "a")

assert.deepStrictEqual(S.decodeSync(schema)(0), "a")

Signature

declare const transformLiteral: <Encoded extends AST.LiteralValue, Type extends AST.LiteralValue>(
  from: Encoded,
  to: Type
) => transformLiteral<Type, Encoded>

Source

Since v3.10.0

transformLiterals

Creates a new Schema which maps between corresponding literal values.

Example

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

const Animal = S.transformLiterals([0, "cat"], [1, "dog"], [2, "cow"])

assert.deepStrictEqual(S.decodeSync(Animal)(1), "dog")

Signature

declare const transformLiterals: {
  <const A extends AST.Members<readonly [from: AST.LiteralValue, to: AST.LiteralValue]>>(
    ...pairs: A
  ): Union<{ -readonly [I in keyof A]: transformLiteral<A[I][1], A[I][0]> }>
  <Encoded extends AST.LiteralValue, Type extends AST.LiteralValue>(
    pairs: [Encoded, Type]
  ): transformLiteral<Type, Encoded>
  <const A extends ReadonlyArray<readonly [from: AST.LiteralValue, to: AST.LiteralValue]>>(
    ...pairs: A
  ): Schema<A[number][1], A[number][0]>
}

Source

Since v3.10.0

decoding

decode

Signature

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

Source

Since v3.10.0

decodeEither

Signature

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

Source

Since v3.10.0

decodeOption

Signature

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

Source

Since v3.10.0

decodePromise

Signature

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

Source

Since v3.10.0

decodeSync

Throws

ParseError

Signature

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

Source

Since v3.10.0

decodeUnknown

Signature

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

Source

Since v3.10.0

decodeUnknownEither

Signature

declare const decodeUnknownEither: <A, I>(
  schema: Schema<A, I, never>,
  options?: ParseOptions
) => (u: unknown, overrideOptions?: ParseOptions) => either_.Either<A, ParseResult.ParseError>

Source

Since v3.10.0

decodeUnknownOption

Signature

declare const decodeUnknownOption: <A, I>(
  schema: Schema<A, I, never>,
  options?: AST.ParseOptions
) => (u: unknown, overrideOptions?: AST.ParseOptions) => option_.Option<A>

Source

Since v3.10.0

decodeUnknownPromise

Signature

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

Source

Since v3.10.0

decodeUnknownSync

Throws

ParseError

Signature

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

Source

Since v3.10.0

deserialize

Signature

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

Source

Since v3.10.0

deserializeExit

Signature

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

Source

Since v3.10.0

deserializeFailure

Signature

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

Source

Since v3.10.0

deserializeSuccess

Signature

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

Source

Since v3.10.0

defect

Defect (class)

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

Source

Since v3.10.0

encoding

encode

Signature

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

Source

Since v3.10.0

encodeEither

Signature

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

Source

Since v3.10.0

encodeOption

Signature

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

Source

Since v3.10.0

encodePromise

Signature

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

Source

Since v3.10.0

encodeSync

Throws

ParseError

Signature

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

Source

Since v3.10.0

encodeUnknown

Signature

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

Source

Since v3.10.0

encodeUnknownEither

Signature

declare const encodeUnknownEither: <A, I>(
  schema: Schema<A, I, never>,
  options?: ParseOptions
) => (u: unknown, overrideOptions?: ParseOptions) => either_.Either<I, ParseResult.ParseError>

Source

Since v3.10.0

encodeUnknownOption

Signature

declare const encodeUnknownOption: <A, I>(
  schema: Schema<A, I, never>,
  options?: AST.ParseOptions
) => (u: unknown, overrideOptions?: AST.ParseOptions) => option_.Option<I>

Source

Since v3.10.0

encodeUnknownPromise

Signature

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

Source

Since v3.10.0

encodeUnknownSync

Throws

ParseError

Signature

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

Source

Since v3.10.0

serialize

Signature

declare const serialize: <A, I, R>(self: Serializable<A, I, R>) => Effect.Effect<I, ParseResult.ParseError, R>

Source

Since v3.10.0

serializeExit

Signature

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

Source

Since v3.10.0

serializeFailure

Signature

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

Source

Since v3.10.0

serializeSuccess

Signature

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

Source

Since v3.10.0

filtering

FilterIssue (interface)

Signature

export interface FilterIssue {
  readonly path: ReadonlyArray<PropertyKey>
  readonly message: string
}

Source

Since v3.10.0

FilterOutput (type alias)

Signature

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

Source

Since v3.10.0

filter

Signature

declare const filter: {
  <C extends A, B extends A, A = C>(
    refinement: (a: A, options: ParseOptions, self: AST.Refinement) => a is B,
    annotations?: Annotations.Filter<C & B, C>
  ): <I, R>(self: Schema<C, I, R>) => refine<C & B, Schema<A, I, R>>
  <A, B extends A>(
    refinement: (a: A, options: ParseOptions, self: AST.Refinement) => a is B,
    annotations?: Annotations.Filter<B, A>
  ): <I, R>(self: Schema<A, I, R>) => refine<B, Schema<A, I, R>>
  <S extends Schema.Any>(
    predicate: (a: Types.NoInfer<Schema.Type<S>>, options: ParseOptions, self: AST.Refinement) => FilterReturnType,
    annotations?: Annotations.Filter<Types.NoInfer<Schema.Type<S>>>
  ): (self: S) => filter<S>
}

Source

Since v3.10.0

formatting

format

Signature

declare const format: <S extends Schema.All>(schema: S) => string

Source

Since v3.10.0

guards

isPropertySignature

Signature

declare const isPropertySignature: (u: unknown) => u is PropertySignature.All

Source

Since v3.10.0

isSchema

Tests if a value is a Schema.

Signature

declare const isSchema: (u: unknown) => u is Schema.Any

Source

Since v3.10.0

model

Schema (interface)

Signature

export interface Schema<in out A, in out I = A, out R = never> extends Schema.Variance<A, I, R>, Pipeable {
  readonly Type: A
  readonly Encoded: I
  readonly Context: R
  readonly ast: AST.AST
  /**
   * Merges a set of new annotations with existing ones, potentially overwriting
   * any duplicates.
   */
  annotations(annotations: Annotations.GenericSchema<A>): Schema<A, I, R>
}

Source

Since v3.10.0

SchemaClass (interface)

Signature

export interface SchemaClass<A, I = A, R = never> extends AnnotableClass<SchemaClass<A, I, R>, A, I, R> {}

Source

Since v3.10.0

Serializable (interface)

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

Signature

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

Source

Since v3.10.0

Serializable (namespace)

Source

Since v3.10.0

Type (type alias)

Signature

type Type<T> = T extends Serializable<infer A, infer _I, infer _R> ? A : never

Source

Since v3.10.0

Encoded (type alias)

Signature

type Encoded<T> = T extends Serializable<infer _A, infer I, infer _R> ? I : never

Source

Since v3.10.0

Context (type alias)

Signature

type Context<T> = T extends Serializable<infer _A, infer _I, infer R> ? R : never

Source

Since v3.10.0

Any (type alias)

Signature

type Any = Serializable<any, any, unknown>

Source

Since v3.10.0

All (type alias)

Signature

type All =
  | Any
  | Serializable<any, never, unknown>
  | Serializable<never, any, unknown>
  | Serializable<never, never, unknown>

Source

Since v3.10.0

SerializableWithResult (interface)

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

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

Source

Since v3.10.0

SerializableWithResult (namespace)

Source

Since v3.10.0

Context (type alias)

Signature

type Context<P> =
  P extends SerializableWithResult<infer _S, infer _SI, infer SR, infer _A, infer _AI, infer _E, infer _EI, infer RR>
    ? SR | RR
    : never

Source

Since v3.10.0

Any (type alias)

Signature

type Any = SerializableWithResult<any, any, any, any, any, any, any, unknown>

Source

Since v3.10.0

All (type alias)

Signature

type All = Any | SerializableWithResult<any, any, any, any, any, never, never, unknown>

Source

Since v3.10.0

WithResult (interface)

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

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

Source

Since v3.10.0

WithResult (namespace)

Source

Since v3.10.0

Success (type alias)

Signature

type Success<T> = T extends WithResult<infer _A, infer _I, infer _E, infer _EI, infer _R> ? _A : never

Source

Since v3.10.0

SuccessEncoded (type alias)

Signature

type SuccessEncoded<T> = T extends WithResult<infer _A, infer _I, infer _E, infer _EI, infer _R> ? _I : never

Source

Since v3.10.0

Failure (type alias)

Signature

type Failure<T> = T extends WithResult<infer _A, infer _I, infer _E, infer _EI, infer _R> ? _E : never

Source

Since v3.10.0

FailureEncoded (type alias)

Signature

type FailureEncoded<T> = T extends WithResult<infer _A, infer _I, infer _E, infer _EI, infer _R> ? _EI : never

Source

Since v3.10.0

Context (type alias)

Signature

type Context<T> = T extends WithResult<infer _SA, infer _SI, infer _FA, infer _FI, infer R> ? R : never

Source

Since v3.10.0

Any (type alias)

Signature

type Any = WithResult<any, any, any, any, unknown>

Source

Since v3.10.0

All (type alias)

Signature

type All = Any | WithResult<any, any, never, never, unknown>

Source

Since v3.10.0

number constructors

Finite (class)

Signature

declare class Finite

Source

Since v3.10.0

Int (class)

Signature

declare class Int

Source

Since v3.10.0

JsonNumber (class)

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.

Example

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

const is = Schema.is(S.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)

Signature

declare class JsonNumber

Source

Since v3.10.0

Negative (class)

Signature

declare class Negative

Source

Since v3.10.0

NonNaN (class)

Signature

declare class NonNaN

Source

Since v3.10.0

NonNegative (class)

Signature

declare class NonNegative

Source

Since v3.10.0

NonNegativeInt

A non-negative integer. +Infinity is excluded.

Signature

declare const NonNegativeInt: refine<number, typeof NonNegative>

Source

Since v3.11.10

NonPositive (class)

Signature

declare class NonPositive

Source

Since v3.10.0

Positive (class)

Signature

declare class Positive

Source

Since v3.10.0

Uint8 (class)

Signature

declare class Uint8

Source

Since v3.11.10

number filters

between

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

Signature

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

Source

Since v3.10.0

finite

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

Signature

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

Source

Since v3.10.0

greaterThan

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

Signature

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

Source

Since v3.10.0

greaterThanOrEqualTo

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

Signature

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

Source

Since v3.10.0

int

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

Signature

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

Source

Since v3.10.0

lessThan

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

Signature

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

Source

Since v3.10.0

lessThanOrEqualTo

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

Signature

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

Source

Since v3.10.0

multipleOf

Signature

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

Source

Since v3.10.0

negative

Signature

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

Source

Since v3.10.0

nonNaN

Signature

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

Source

Since v3.10.0

nonNegative

Signature

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

Source

Since v3.10.0

nonPositive

Signature

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

Source

Since v3.10.0

positive

Signature

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

Source

Since v3.10.0

number transformations

NumberFromString (class)

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

Source

Since v3.10.0

clamp

Clamps a number between a minimum and a maximum value.

Signature

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

Source

Since v3.10.0

parseNumber

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 const parseNumber: <S extends Schema.Any, A extends string>(
  self: S & Schema<A, Schema.Encoded<S>, Schema.Context<S>>
) => transformOrFail<S, typeof Number$>

Source

Since v3.10.0

primitives

Any (class)

Signature

declare class Any

Source

Since v3.10.0

BigIntFromSelf (class)

Signature

declare class BigIntFromSelf

Source

Since v3.10.0

Boolean

Signature

declare const Boolean: typeof Boolean$

Source

Since v3.10.0

Never (class)

Signature

declare class Never

Source

Since v3.10.0

Null (class)

Signature

declare class Null

Source

Since v3.10.0

Number

Signature

declare const Number: typeof Number$

Source

Since v3.10.0

Object

Signature

declare const Object: typeof Object$

Source

Since v3.10.0

String

Signature

declare const String: typeof String$

Source

Since v3.10.0

SymbolFromSelf (class)

Signature

declare class SymbolFromSelf

Source

Since v3.10.0

Undefined (class)

Signature

declare class Undefined

Source

Since v3.10.0

Unknown (class)

Signature

declare class Unknown

Source

Since v3.10.0

Void (class)

Signature

declare class Void

Source

Since v3.10.0

renaming

rename

Signature

declare const rename: {
  <A, const M extends { readonly [K in keyof A]?: PropertyKey } & { readonly [K in Exclude<keyof M, keyof A>]: never }>(
    mapping: M
  ): <I, R>(self: Schema<A, I, R>) => SchemaClass<Simplify<Rename<A, M>>, I, R>
  <
    A,
    I,
    R,
    const M extends { readonly [K in keyof A]?: PropertyKey } & { readonly [K in Exclude<keyof M, keyof A>]: never }
  >(
    self: Schema<A, I, R>,
    mapping: M
  ): SchemaClass<Simplify<Rename<A, M>>, I, R>
}

Source

Since v3.10.0

schema id

BetweenBigDecimalSchemaId

Signature

declare const BetweenBigDecimalSchemaId: unique symbol

Source

Since v3.10.0

BetweenBigIntSchemaId

Signature

declare const BetweenBigIntSchemaId: unique symbol

Source

Since v3.10.0

BetweenBigIntSchemaId (type alias)

Signature

type BetweenBigIntSchemaId = typeof BetweenBigIntSchemaId

Source

Since v3.10.0

BetweenDateSchemaId

Signature

declare const BetweenDateSchemaId: unique symbol

Source

Since v3.10.0

BetweenDurationSchemaId

Signature

declare const BetweenDurationSchemaId: unique symbol

Source

Since v3.10.0

BetweenSchemaId

Signature

declare const BetweenSchemaId: unique symbol

Source

Since v3.10.0

BetweenSchemaId (type alias)

Signature

type BetweenSchemaId = typeof BetweenSchemaId

Source

Since v3.10.0

BrandSchemaId

Signature

declare const BrandSchemaId: unique symbol

Source

Since v3.10.0

CapitalizedSchemaId

Signature

declare const CapitalizedSchemaId: unique symbol

Source

Since v3.10.0

DateFromSelfSchemaId

Signature

declare const DateFromSelfSchemaId: unique symbol

Source

Since v3.11.8

DateFromSelfSchemaId (type alias)

Signature

type DateFromSelfSchemaId = typeof DateFromSelfSchemaId

Source

Since v3.11.8

EndsWithSchemaId

Signature

declare const EndsWithSchemaId: unique symbol

Source

Since v3.10.0

FiniteSchemaId

Signature

declare const FiniteSchemaId: unique symbol

Source

Since v3.10.0

FiniteSchemaId (type alias)

Signature

type FiniteSchemaId = typeof FiniteSchemaId

Source

Since v3.10.0

GreaterThanBigDecimalSchemaId

Signature

declare const GreaterThanBigDecimalSchemaId: unique symbol

Source

Since v3.10.0

GreaterThanBigIntSchemaId

Signature

declare const GreaterThanBigIntSchemaId: unique symbol

Source

Since v3.10.0

GreaterThanBigIntSchemaId (type alias)

Signature

type GreaterThanBigIntSchemaId = typeof GreaterThanBigIntSchemaId

Source

Since v3.10.0

GreaterThanDateSchemaId

Signature

declare const GreaterThanDateSchemaId: unique symbol

Source

Since v3.10.0

GreaterThanDurationSchemaId

Signature

declare const GreaterThanDurationSchemaId: unique symbol

Source

Since v3.10.0

GreaterThanOrEqualToBigDecimalSchemaId

Signature

declare const GreaterThanOrEqualToBigDecimalSchemaId: unique symbol

Source

Since v3.10.0

GreaterThanOrEqualToBigIntSchemaId

Signature

declare const GreaterThanOrEqualToBigIntSchemaId: unique symbol

Source

Since v3.10.0

GreaterThanOrEqualToBigIntSchemaId (type alias)

Signature

type GreaterThanOrEqualToBigIntSchemaId = typeof GreaterThanOrEqualToBigIntSchemaId

Source

Since v3.10.0

GreaterThanOrEqualToDateSchemaId

Signature

declare const GreaterThanOrEqualToDateSchemaId: unique symbol

Source

Since v3.10.0

GreaterThanOrEqualToDurationSchemaId

Signature

declare const GreaterThanOrEqualToDurationSchemaId: unique symbol

Source

Since v3.10.0

GreaterThanOrEqualToSchemaId

Signature

declare const GreaterThanOrEqualToSchemaId: unique symbol

Source

Since v3.10.0

GreaterThanOrEqualToSchemaId (type alias)

Signature

type GreaterThanOrEqualToSchemaId = typeof GreaterThanOrEqualToSchemaId

Source

Since v3.10.0

GreaterThanSchemaId

Signature

declare const GreaterThanSchemaId: unique symbol

Source

Since v3.10.0

GreaterThanSchemaId (type alias)

Signature

type GreaterThanSchemaId = typeof GreaterThanSchemaId

Source

Since v3.10.0

IncludesSchemaId

Signature

declare const IncludesSchemaId: unique symbol

Source

Since v3.10.0

InstanceOfSchemaId

Signature

declare const InstanceOfSchemaId: unique symbol

Source

Since v3.10.0

IntSchemaId

Signature

declare const IntSchemaId: unique symbol

Source

Since v3.10.0

IntSchemaId (type alias)

Signature

type IntSchemaId = typeof IntSchemaId

Source

Since v3.10.0

ItemsCountSchemaId

Signature

declare const ItemsCountSchemaId: unique symbol

Source

Since v3.10.0

ItemsCountSchemaId (type alias)

Signature

type ItemsCountSchemaId = typeof ItemsCountSchemaId

Source

Since v3.10.0

JsonNumberSchemaId

Signature

declare const JsonNumberSchemaId: unique symbol

Source

Since v3.10.0

JsonNumberSchemaId (type alias)

Signature

type JsonNumberSchemaId = typeof JsonNumberSchemaId

Source

Since v3.10.0

LengthSchemaId

Signature

declare const LengthSchemaId: unique symbol

Source

Since v3.10.0

LengthSchemaId (type alias)

Signature

type LengthSchemaId = typeof LengthSchemaId

Source

Since v3.10.0

LessThanBigDecimalSchemaId

Signature

declare const LessThanBigDecimalSchemaId: unique symbol

Source

Since v3.10.0

LessThanBigIntSchemaId

Signature

declare const LessThanBigIntSchemaId: unique symbol

Source

Since v3.10.0

LessThanBigIntSchemaId (type alias)

Signature

type LessThanBigIntSchemaId = typeof LessThanBigIntSchemaId

Source

Since v3.10.0

LessThanDateSchemaId

Signature

declare const LessThanDateSchemaId: unique symbol

Source

Since v3.10.0

LessThanDurationSchemaId

Signature

declare const LessThanDurationSchemaId: unique symbol

Source

Since v3.10.0

LessThanOrEqualToBigDecimalSchemaId

Signature

declare const LessThanOrEqualToBigDecimalSchemaId: unique symbol

Source

Since v3.10.0

LessThanOrEqualToBigIntSchemaId

Signature

declare const LessThanOrEqualToBigIntSchemaId: unique symbol

Source

Since v3.10.0

LessThanOrEqualToBigIntSchemaId (type alias)

Signature

type LessThanOrEqualToBigIntSchemaId = typeof LessThanOrEqualToBigIntSchemaId

Source

Since v3.10.0

LessThanOrEqualToDateSchemaId

Signature

declare const LessThanOrEqualToDateSchemaId: unique symbol

Source

Since v3.10.0

LessThanOrEqualToDurationSchemaId

Signature

declare const LessThanOrEqualToDurationSchemaId: unique symbol

Source

Since v3.10.0

LessThanOrEqualToSchemaId

Signature

declare const LessThanOrEqualToSchemaId: unique symbol

Source

Since v3.10.0

LessThanOrEqualToSchemaId (type alias)

Signature

type LessThanOrEqualToSchemaId = typeof LessThanOrEqualToSchemaId

Source

Since v3.10.0

LessThanSchemaId

Signature

declare const LessThanSchemaId: unique symbol

Source

Since v3.10.0

LessThanSchemaId (type alias)

Signature

type LessThanSchemaId = typeof LessThanSchemaId

Source

Since v3.10.0

LowercasedSchemaId

Signature

declare const LowercasedSchemaId: unique symbol

Source

Since v3.10.0

MaxItemsSchemaId

Signature

declare const MaxItemsSchemaId: unique symbol

Source

Since v3.10.0

MaxItemsSchemaId (type alias)

Signature

type MaxItemsSchemaId = typeof MaxItemsSchemaId

Source

Since v3.10.0

MaxLengthSchemaId

Signature

declare const MaxLengthSchemaId: unique symbol

Source

Since v3.10.0

MaxLengthSchemaId (type alias)

Signature

type MaxLengthSchemaId = typeof MaxLengthSchemaId

Source

Since v3.10.0

MinItemsSchemaId

Signature

declare const MinItemsSchemaId: unique symbol

Source

Since v3.10.0

MinItemsSchemaId (type alias)

Signature

type MinItemsSchemaId = typeof MinItemsSchemaId

Source

Since v3.10.0

MinLengthSchemaId

Signature

declare const MinLengthSchemaId: unique symbol

Source

Since v3.10.0

MinLengthSchemaId (type alias)

Signature

type MinLengthSchemaId = typeof MinLengthSchemaId

Source

Since v3.10.0

MultipleOfSchemaId

Signature

declare const MultipleOfSchemaId: unique symbol

Source

Since v3.10.0

NegativeBigDecimalSchemaId

Signature

declare const NegativeBigDecimalSchemaId: unique symbol

Source

Since v3.10.0

NonNaNSchemaId

Signature

declare const NonNaNSchemaId: unique symbol

Source

Since v3.10.0

NonNaNSchemaId (type alias)

Signature

type NonNaNSchemaId = typeof NonNaNSchemaId

Source

Since v3.10.0

NonNegativeBigDecimalSchemaId

Signature

declare const NonNegativeBigDecimalSchemaId: unique symbol

Source

Since v3.10.0

NonPositiveBigDecimalSchemaId

Signature

declare const NonPositiveBigDecimalSchemaId: unique symbol

Source

Since v3.10.0

PatternSchemaId

Signature

declare const PatternSchemaId: unique symbol

Source

Since v3.10.0

PositiveBigDecimalSchemaId

Signature

declare const PositiveBigDecimalSchemaId: unique symbol

Source

Since v3.10.0

StartsWithSchemaId

Signature

declare const StartsWithSchemaId: unique symbol

Source

Since v3.10.0

TrimmedSchemaId

Signature

declare const TrimmedSchemaId: unique symbol

Source

Since v3.10.0

ULIDSchemaId

Signature

declare const ULIDSchemaId: unique symbol

Source

Since v3.10.0

UUIDSchemaId

Signature

declare const UUIDSchemaId: unique symbol

Source

Since v3.10.0

UncapitalizedSchemaId

Signature

declare const UncapitalizedSchemaId: unique symbol

Source

Since v3.10.0

UppercasedSchemaId

Signature

declare const UppercasedSchemaId: unique symbol

Source

Since v3.10.0

ValidDateSchemaId

Signature

declare const ValidDateSchemaId: unique symbol

Source

Since v3.10.0

string constructors

Capitalized (class)

Signature

declare class Capitalized

Source

Since v3.10.0

Char (class)

A schema representing a single character.

Signature

declare class Char

Source

Since v3.10.0

Lowercased (class)

Signature

declare class Lowercased

Source

Since v3.10.0

NonEmptyString (class)

Signature

declare class NonEmptyString

Source

Since v3.10.0

NonEmptyTrimmedString (class)

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

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")

Signature

declare class NonEmptyTrimmedString

Source

Since v3.10.0

Trimmed (class)

Signature

declare class Trimmed

Source

Since v3.10.0

ULID (class)

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

Source

Since v3.10.0

UUID (class)

Represents a Universally Unique Identifier (UUID).

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

Signature

declare class UUID

Source

Since v3.10.0

Uncapitalized (class)

Signature

declare class Uncapitalized

Source

Since v3.10.0

Uppercased (class)

Signature

declare class Uppercased

Source

Since v3.10.0

string filters

capitalized

Verifies that a string is capitalized.

Signature

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

Source

Since v3.10.0

endsWith

Signature

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

Source

Since v3.10.0

includes

Signature

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

Source

Since v3.10.0

length

Signature

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

Source

Since v3.10.0

lowercased

Verifies that a string is lowercased.

Signature

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

Source

Since v3.10.0

maxLength

Signature

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

Source

Since v3.10.0

minLength

Signature

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

Source

Since v3.10.0

nonEmptyString

Signature

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

Source

Since v3.10.0

pattern

Signature

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

Source

Since v3.10.0

startsWith

Signature

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

Source

Since v3.10.0

trimmed

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 const trimmed: <S extends Schema.Any>(
  annotations?: Annotations.Filter<Schema.Type<S>>
) => <A extends string>(self: S & Schema<A, Schema.Encoded<S>, Schema.Context<S>>) => filter<S>

Source

Since v3.10.0

uncapitalized

Verifies that a string is uncapitalized.

Signature

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

Source

Since v3.10.0

uppercased

Verifies that a string is uppercased.

Signature

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

Source

Since v3.10.0

string transformations

Capitalize (class)

This schema converts a string to capitalized one.

Signature

declare class Capitalize

Source

Since v3.10.0

Lowercase (class)

This schema converts a string to lowercase.

Signature

declare class Lowercase

Source

Since v3.10.0

StringFromBase64

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

Signature

declare const StringFromBase64: Schema<string, string, never>

Source

Since v3.10.0

StringFromBase64Url

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

Signature

declare const StringFromBase64Url: Schema<string, string, never>

Source

Since v3.10.0

StringFromHex

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

Signature

declare const StringFromHex: Schema<string, string, never>

Source

Since v3.10.0

StringFromUriComponent

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

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

Signature

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

Source

Since v3.12.0

Trim (class)

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

Signature

declare class Trim

Source

Since v3.10.0

Uncapitalize (class)

This schema converts a string to uncapitalized one.

Signature

declare class Uncapitalize

Source

Since v3.10.0

Uppercase (class)

This schema converts a string to uppercase.

Signature

declare class Uppercase

Source

Since v3.10.0

parseJson

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.

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 }
)

Signature

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

Source

Since v3.10.0

split

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

Signature

declare const split: (separator: string) => transform<SchemaClass<string>, Array$<typeof String$>>

Source

Since v3.10.0

struct transformations

omit

Signature

declare const omit: <A, I, Keys extends ReadonlyArray<keyof A & keyof I>>(
  ...keys: Keys
) => <R>(self: Schema<A, I, R>) => SchemaClass<Simplify<Omit<A, Keys[number]>>, Simplify<Omit<I, Keys[number]>>, R>

Source

Since v3.10.0

pick

Signature

declare const pick: <A, I, Keys extends ReadonlyArray<keyof A & keyof I>>(
  ...keys: Keys
) => <R>(self: Schema<A, I, R>) => SchemaClass<Simplify<Pick<A, Keys[number]>>, Simplify<Pick<I, Keys[number]>>, R>

Source

Since v3.10.0

pluck

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

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 ] }

Signature

declare const pluck: {
  <A, I, K extends keyof A & keyof I>(
    key: K
  ): <R>(schema: Schema<A, I, R>) => SchemaClass<A[K], Simplify<Pick<I, K>>, R>
  <A, I, R, K extends keyof A & keyof I>(schema: Schema<A, I, R>, key: K): SchemaClass<A[K], Simplify<Pick<I, K>>, R>
}

Source

Since v3.10.0

symbol

PropertySignatureTypeId

Signature

declare const PropertySignatureTypeId: unique symbol

Source

Since v3.10.0

PropertySignatureTypeId (type alias)

Signature

type PropertySignatureTypeId = typeof PropertySignatureTypeId

Source

Since v3.10.0

RefineSchemaId

Signature

declare const RefineSchemaId: unique symbol

Source

Since v3.10.0

RefineSchemaId (type alias)

Signature

type RefineSchemaId = typeof RefineSchemaId

Source

Since v3.10.0

TypeId

Signature

declare const TypeId: unique symbol

Source

Since v3.10.0

TypeId (type alias)

Signature

type TypeId = typeof TypeId

Source

Since v3.10.0

symbolSerializable

Signature

declare const symbolSerializable: unique symbol

Source

Since v3.10.0

symbolWithResult

Signature

declare const symbolWithResult: unique symbol

Source

Since v3.10.0

symbol transformations

Symbol

Converts a string key into a globally shared symbol.

Signature

declare const Symbol: typeof Symbol$

Source

Since v3.10.0

template literal

TemplateLiteral

Signature

declare const TemplateLiteral: <Params extends array_.NonEmptyReadonlyArray<TemplateLiteralParameter>>(
  ...[head, ...tail]: Params
) => TemplateLiteral<GetTemplateLiteralType<Params>>

Source

Since v3.10.0

TemplateLiteralParser

Signature

declare const TemplateLiteralParser: <Params extends array_.NonEmptyReadonlyArray<TemplateLiteralParserParameters>>(
  ...params: Params
) => TemplateLiteralParser<Params>

Source

Since v3.10.0

transformations

filterEffect

Signature

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

Source

Since v3.10.0

transform

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 Schema.Any, From extends Schema.Any>(
    to: To,
    options:
      | {
          readonly decode: (fromA: Schema.Type<From>, fromI: Schema.Encoded<From>) => Schema.Encoded<To>
          readonly encode: (toI: Schema.Encoded<To>, toA: Schema.Type<To>) => Schema.Type<From>
          readonly strict?: true
        }
      | {
          readonly decode: (fromA: Schema.Type<From>, fromI: Schema.Encoded<From>) => unknown
          readonly encode: (toI: Schema.Encoded<To>, toA: Schema.Type<To>) => unknown
          readonly strict: false
        }
  ): (from: From) => transform<From, To>
  <To extends Schema.Any, From extends Schema.Any>(
    from: From,
    to: To,
    options:
      | {
          readonly decode: (fromA: Schema.Type<From>, fromI: Schema.Encoded<From>) => Schema.Encoded<To>
          readonly encode: (toI: Schema.Encoded<To>, toA: Schema.Type<To>) => Schema.Type<From>
          readonly strict?: true
        }
      | {
          readonly decode: (fromA: Schema.Type<From>, fromI: Schema.Encoded<From>) => unknown
          readonly encode: (toI: Schema.Encoded<To>, toA: Schema.Type<To>) => unknown
          readonly strict: false
        }
  ): transform<From, To>
}

Source

Since v3.10.0

transformOrFail

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 Schema.Any, From extends Schema.Any, RD, RE>(
    to: To,
    options:
      | {
          readonly decode: (
            fromA: Schema.Type<From>,
            options: ParseOptions,
            ast: AST.Transformation,
            fromI: Schema.Encoded<From>
          ) => Effect.Effect<Schema.Encoded<To>, ParseResult.ParseIssue, RD>
          readonly encode: (
            toI: Schema.Encoded<To>,
            options: ParseOptions,
            ast: AST.Transformation,
            toA: Schema.Type<To>
          ) => Effect.Effect<Schema.Type<From>, ParseResult.ParseIssue, RE>
          readonly strict?: true
        }
      | {
          readonly decode: (
            fromA: Schema.Type<From>,
            options: ParseOptions,
            ast: AST.Transformation,
            fromI: Schema.Encoded<From>
          ) => Effect.Effect<unknown, ParseResult.ParseIssue, RD>
          readonly encode: (
            toI: Schema.Encoded<To>,
            options: ParseOptions,
            ast: AST.Transformation,
            toA: Schema.Type<To>
          ) => Effect.Effect<unknown, ParseResult.ParseIssue, RE>
          readonly strict: false
        }
  ): (from: From) => transformOrFail<From, To, RD | RE>
  <To extends Schema.Any, From extends Schema.Any, RD, RE>(
    from: From,
    to: To,
    options:
      | {
          readonly decode: (
            fromA: Schema.Type<From>,
            options: ParseOptions,
            ast: AST.Transformation,
            fromI: Schema.Encoded<From>
          ) => Effect.Effect<Schema.Encoded<To>, ParseResult.ParseIssue, RD>
          readonly encode: (
            toI: Schema.Encoded<To>,
            options: ParseOptions,
            ast: AST.Transformation,
            toA: Schema.Type<To>
          ) => Effect.Effect<Schema.Type<From>, ParseResult.ParseIssue, RE>
          readonly strict?: true
        }
      | {
          readonly decode: (
            fromA: Schema.Type<From>,
            options: ParseOptions,
            ast: AST.Transformation,
            fromI: Schema.Encoded<From>
          ) => Effect.Effect<unknown, ParseResult.ParseIssue, RD>
          readonly encode: (
            toI: Schema.Encoded<To>,
            options: ParseOptions,
            ast: AST.Transformation,
            toA: Schema.Type<To>
          ) => Effect.Effect<unknown, ParseResult.ParseIssue, RE>
          readonly strict: false
        }
  ): transformOrFail<From, To, RD | RE>
}

Source

Since v3.10.0

utils

Element (namespace)

Source

Since v3.10.0

Annotations (interface)

Signature

export interface Annotations<A> extends Annotations.Doc<A> {
  readonly missingMessage?: AST.MissingMessageAnnotation
}

Source

Since v3.10.0

Token (type alias)

Signature

type Token = "" | "?"

Source

Since v3.10.0

EnumsDefinition (type alias)

Signature

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

Source

Since v3.10.0

IndexSignature (namespace)

Source

Since v3.10.0

Record (type alias)

Signature

type Record = { readonly key: Schema.All; readonly value: Schema.All }

Source

Since v3.10.0

Records (type alias)

Signature

type Records = ReadonlyArray<Record>

Source

Since v3.10.0

NonEmptyRecords (type alias)

Signature

type NonEmptyRecords = array_.NonEmptyReadonlyArray<Record>

Source

Since v3.10.0

Type (type alias)

Signature

type Type<Records> = MergeTuple<{
  readonly [K in keyof Records]: {
    readonly [P in Schema.Type<Records[K]["key"]>]: Schema.Type<Records[K]["value"]>
  }
}>

Source

Since v3.10.0

Encoded (type alias)

Signature

type Encoded<Records> = MergeTuple<{
  readonly [K in keyof Records]: {
    readonly [P in Schema.Encoded<Records[K]["key"]>]: Schema.Encoded<Records[K]["value"]>
  }
}>

Source

Since v3.10.0

Context (type alias)

Signature

type Context<Records> = {
  [K in keyof Records]: Schema.Context<Records[K]["key"]> | Schema.Context<Records[K]["value"]>
}[number]

Source

Since v3.10.0

OptionalOptions (type alias)

Signature

type OptionalOptions<A> =
  | {
      readonly default?: never
      readonly as?: never
      readonly exact?: true
      readonly nullable?: true
    }
  | {
      readonly default: LazyArg<A>
      readonly as?: never
      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

Source

Since v3.10.0

ParseJsonOptions (type alias)

Signature

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

Source

Since v3.10.0

PropertyKey

Signature

declare const PropertyKey: typeof PropertyKey$

Source

Since v3.12.5

PropertySignature (namespace)

Source

Since v3.10.0

Annotations (interface)

Signature

export interface Annotations<A> extends Annotations.Doc<A> {
  readonly missingMessage?: AST.MissingMessageAnnotation
}

Source

Since v3.10.0

Token (type alias)

Signature

type Token = "?:" | ":"

Source

Since v3.10.0

Any (type alias)

Signature

type Any<Key> = PropertySignature<Token, any, Key, Token, any, boolean, unknown>

Source

Since v3.10.0

All (type alias)

Signature

type All<Key> =
  | Any<Key>
  | PropertySignature<Token, never, Key, Token, any, boolean, unknown>
  | PropertySignature<Token, any, Key, Token, never, boolean, unknown>
  | PropertySignature<Token, never, Key, Token, never, boolean, unknown>

Source

Since v3.10.0

AST (type alias)

Signature

type AST = PropertySignatureDeclaration | PropertySignatureTransformation

Source

Since v3.10.0

Schema (namespace)

Source

Since v3.10.0

Variance (interface)

Signature

export interface Variance<A, I, R> {
  readonly [TypeId]: {
    readonly _A: Types.Invariant<A>
    readonly _I: Types.Invariant<I>
    readonly _R: Types.Covariant<R>
  }
}

Source

Since v3.10.0

Type (type alias)

Signature

type Type<S> = S extends Schema.Variance<infer A, infer _I, infer _R> ? A : never

Source

Since v3.10.0

Encoded (type alias)

Signature

type Encoded<S> = S extends Schema.Variance<infer _A, infer I, infer _R> ? I : never

Source

Since v3.10.0

Context (type alias)

Signature

type Context<S> = S extends Schema.Variance<infer _A, infer _I, infer R> ? R : never

Source

Since v3.10.0

ToAsserts (type alias)

Signature

type ToAsserts<S> = (input: unknown, options?: AST.ParseOptions) => asserts input is Schema.Type<S>

Source

Since v3.10.0

Any (type alias)

Any schema, except for never.

Signature

type Any = Schema<any, any, unknown>

Source

Since v3.10.0

AnyNoContext (type alias)

Any schema with Context = never, except for never.

Signature

type AnyNoContext = Schema<any, any, never>

Source

Since v3.10.0

All (type alias)

Any schema, including never.

Signature

type All = Any | Schema<any, never, unknown> | Schema<never, any, unknown> | Schema<never, never, unknown>

Source

Since v3.10.0

AsSchema (type alias)

Type-level counterpart of Schema.asSchema function.

Signature

type AsSchema<S> = Schema<Type<S>, Encoded<S>, Context<S>>

Source

Since v3.10.0

Simplify (type alias)

Signature

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

Source

Since v3.10.0

SimplifyMutable (type alias)

Signature

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

Source

Since v3.10.0

Struct (namespace)

Source

Since v3.10.0

Field (type alias)

Useful for creating a type that can be used to add custom constraints to the fields of a struct.

import { Schema } from "effect"

const f = <Fields extends Record<"a" | "b", Schema.Struct.Field>>(schema: Schema.Struct<Fields>) => {
  return schema.omit("a")
}

//      ┌─── Schema.Struct<{ b: typeof Schema.Number; }>
//      ▼
const result = f(Schema.Struct({ a: Schema.String, b: Schema.Number }))

Signature

type Field = Schema.All | PropertySignature.All

Source

Since v3.13.11

Fields (type alias)

Signature

type Fields = { readonly [x: PropertyKey]: Field }

Source

Since v3.10.0

Type (type alias)

Signature

type Type<F> =
  Types.UnionToIntersection<
    {
      [K in keyof F]: F[K] extends OptionalTypePropertySignature
        ? { readonly [H in K]?: Schema.Type<F[H]> }
        : { readonly [h in K]: Schema.Type<F[h]> }
    }[keyof F]
  > extends infer Q
    ? Q
    : never

Source

Since v3.10.0

Encoded (type alias)

Signature

type Encoded<F> = { readonly [K in Exclude<keyof F, EncodedOptionalKeys<F>> as Key<F, K>]: Schema.Encoded<F[K]> } & {
  readonly [K in EncodedOptionalKeys<F> as Key<F, K>]?: Schema.Encoded<F[K]>
}

Source

Since v3.10.0

Context (type alias)

Signature

type Context<F> = Schema.Context<F[keyof F]>

Source

Since v3.10.0

Constructor (type alias)

Signature

type Constructor<F> =
  Types.UnionToIntersection<
    {
      [K in keyof F]: F[K] extends OptionalTypePropertySignature
        ? { readonly [H in K]?: Schema.Type<F[H]> }
        : F[K] extends PropertySignatureWithDefault
          ? { readonly [H in K]?: Schema.Type<F[H]> }
          : { readonly [h in K]: Schema.Type<F[h]> }
    }[keyof F]
  > extends infer Q
    ? Q
    : never

Source

Since v3.10.0

TaggedRequest (interface)

Signature

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

Source

Since v3.10.0

TaggedRequest (namespace)

Source

Since v3.10.0

Any (type alias)

Signature

type Any = TaggedRequest<string, any, any, any, any, any, any, any, unknown>

Source

Since v3.10.0

All (type alias)

Signature

type All = Any | TaggedRequest<string, any, any, any, any, any, never, never, unknown>

Source

Since v3.10.0

TupleType (namespace)

Source

Since v3.10.0

Elements (type alias)

Signature

type Elements = ReadonlyArray<Schema.Any | Element<Schema.Any, Element.Token>>

Source

Since v3.10.0

Rest (type alias)

Signature

type Rest = ReadonlyArray<Schema.Any | Element<Schema.Any, "">>

Source

Since v3.10.0

Type (type alias)

Signature

type Type<Elements, Rest> = Rest extends [infer Head, ...infer Tail]
  ? Readonly<
      [
        ...ElementsType<Elements>,
        ...ReadonlyArray<Schema.Type<Head>>,
        ...{ readonly [K in keyof Tail]: Schema.Type<Tail[K]> }
      ]
    >
  : ElementsType<Elements>

Source

Since v3.10.0

Encoded (type alias)

Signature

type Encoded<Elements, Rest> = Rest extends [infer Head, ...infer Tail]
  ? Readonly<
      [
        ...ElementsEncoded<Elements>,
        ...ReadonlyArray<Schema.Encoded<Head>>,
        ...{ readonly [K in keyof Tail]: Schema.Encoded<Tail[K]> }
      ]
    >
  : ElementsEncoded<Elements>

Source

Since v3.10.0

TypeLiteral (namespace)

Source

Since v3.10.0

Type (type alias)

Signature

type Type<Fields, Records> = Struct.Type<Fields> & IndexSignature.Type<Records>

Source

Since v3.10.0

Encoded (type alias)

Signature

type Encoded<Fields, Records> = Struct.Encoded<Fields> & IndexSignature.Encoded<Records>

Source

Since v3.10.0

Constructor (type alias)

Signature

type Constructor<Fields, Records> = Struct.Constructor<Fields> & IndexSignature.Type<Records>

Source

Since v3.10.0

asSchema

Signature

declare const asSchema: <S extends Schema.All>(
  schema: S
) => Schema<Schema.Type<S>, Schema.Encoded<S>, Schema.Context<S>>

Source

Since v3.10.0

asSerializable

Signature

declare const asSerializable: <S extends Serializable.All>(
  serializable: S
) => Serializable<Serializable.Type<S>, Serializable.Encoded<S>, Serializable.Context<S>>

Source

Since v3.10.0

asSerializableWithResult

Signature

declare const asSerializableWithResult: <SWR extends SerializableWithResult.All>(
  procedure: SWR
) => SerializableWithResult<
  Serializable.Type<SWR>,
  Serializable.Encoded<SWR>,
  Serializable.Context<SWR>,
  WithResult.Success<SWR>,
  WithResult.SuccessEncoded<SWR>,
  WithResult.Failure<SWR>,
  WithResult.FailureEncoded<SWR>,
  WithResult.Context<SWR>
>

Source

Since v3.10.0

asWithResult

Signature

declare const asWithResult: <WR extends WithResult.All>(
  withExit: WR
) => WithResult<
  WithResult.Success<WR>,
  WithResult.SuccessEncoded<WR>,
  WithResult.Failure<WR>,
  WithResult.FailureEncoded<WR>,
  WithResult.Context<WR>
>

Source

Since v3.10.0

element

Signature

declare const element: <S extends Schema.Any>(self: S) => Element<S, "">

Source

Since v3.10.0

encodedBoundSchema

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

Signature

declare const encodedBoundSchema: <A, I, R>(schema: Schema<A, I, R>) => SchemaClass<I>

Source

Since v3.10.0

encodedSchema

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 const encodedSchema: <A, I, R>(schema: Schema<A, I, R>) => SchemaClass<I>

Source

Since v3.10.0

optionalElement

Signature

declare const optionalElement: <S extends Schema.Any>(self: S) => Element<S, "?">

Source

Since v3.10.0

tag

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.

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 })

See

  • TaggedStruct

Signature

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

Source

Since v3.10.0

typeSchema

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 const typeSchema: <A, I, R>(schema: Schema<A, I, R>) => SchemaClass<A>

Source

Since v3.10.0

validation

asserts

By default the option exact is set to true.

Throws

ParseError

Signature

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

Source

Since v3.10.0

is

By default the option exact is set to true.

Signature

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

Source

Since v3.10.0

validate

Signature

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

Source

Since v3.10.0

validateEither

Signature

declare const validateEither: <A, I, R>(
  schema: Schema<A, I, R>,
  options?: ParseOptions
) => (u: unknown, overrideOptions?: ParseOptions) => either_.Either<A, ParseResult.ParseError>

Source

Since v3.10.0

validateOption

Signature

declare const validateOption: <A, I, R>(
  schema: Schema<A, I, R>,
  options?: AST.ParseOptions
) => (u: unknown, overrideOptions?: AST.ParseOptions) => option_.Option<A>

Source

Since v3.10.0

validatePromise

Signature

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

Source

Since v3.10.0

validateSync

Throws

ParseError

Signature

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

Source

Since v3.10.0