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

Schema overview

Added in v1.0.0


Table of contents


BigDecimal constructors

BigDecimalFromSelf

Signature

export declare const BigDecimalFromSelf: BigDecimalFromSelf

Added in v1.0.0

NegativeBigDecimalFromSelf

Signature

export declare const NegativeBigDecimalFromSelf: any

Added in v1.0.0

NonNegativeBigDecimalFromSelf

Signature

export declare const NonNegativeBigDecimalFromSelf: any

Added in v1.0.0

NonPositiveBigDecimalFromSelf

Signature

export declare const NonPositiveBigDecimalFromSelf: any

Added in v1.0.0

PositiveBigDecimalFromSelf

Signature

export declare const PositiveBigDecimalFromSelf: any

Added in v1.0.0

BigDecimal filters

betweenBigDecimal

Signature

export declare const betweenBigDecimal: <A extends bigDecimal_.BigDecimal>(
  minimum: bigDecimal_.BigDecimal,
  maximum: bigDecimal_.BigDecimal,
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

greaterThanBigDecimal

Signature

export declare const greaterThanBigDecimal: <A extends bigDecimal_.BigDecimal>(
  min: bigDecimal_.BigDecimal,
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

greaterThanOrEqualToBigDecimal

Signature

export declare const greaterThanOrEqualToBigDecimal: <A extends bigDecimal_.BigDecimal>(
  min: bigDecimal_.BigDecimal,
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

lessThanBigDecimal

Signature

export declare const lessThanBigDecimal: <A extends bigDecimal_.BigDecimal>(
  max: bigDecimal_.BigDecimal,
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

lessThanOrEqualToBigDecimal

Signature

export declare const lessThanOrEqualToBigDecimal: <A extends bigDecimal_.BigDecimal>(
  max: bigDecimal_.BigDecimal,
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

negativeBigDecimal

Signature

export declare const negativeBigDecimal: <A extends bigDecimal_.BigDecimal>(
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

nonNegativeBigDecimal

Signature

export declare const nonNegativeBigDecimal: <A extends bigDecimal_.BigDecimal>(
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

nonPositiveBigDecimal

Signature

export declare const nonPositiveBigDecimal: <A extends bigDecimal_.BigDecimal>(
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

positiveBigDecimal

Signature

export declare const positiveBigDecimal: <A extends bigDecimal_.BigDecimal>(
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

BigDecimal transformations

BigDecimal

Signature

export declare const BigDecimal: BigDecimal

Added in v1.0.0

BigDecimalFromNumber

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

export declare const BigDecimalFromNumber: BigDecimalFromNumber

Added in v1.0.0

clampBigDecimal

Clamps a BigDecimal between a minimum and a maximum value.

Signature

export declare const clampBigDecimal: (
  minimum: bigDecimal_.BigDecimal,
  maximum: bigDecimal_.BigDecimal
) => <R, I, A extends bigDecimal_.BigDecimal>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

Cause transformations

cause

Signature

export declare const cause: <E extends Schema.All, DR = never>({
  defect,
  error
}: {
  readonly error: E
  readonly defect?: Schema<unknown, unknown, DR> | undefined
}) => cause<E, DR>

Added in v1.0.0

causeDefectUnknown

Signature

export declare const causeDefectUnknown: $unknown

Added in v1.0.0

causeFromSelf

Signature

export declare const causeFromSelf: <E extends Schema.Any, DR = never>({
  defect,
  error
}: {
  readonly error: E
  readonly defect?: Schema<unknown, unknown, DR> | undefined
}) => causeFromSelf<E, DR>

Added in v1.0.0

Cause utils

CauseEncoded (type alias)

Signature

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

Added in v1.0.0

Chunk transformations

chunk

Signature

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

Added in v1.0.0

chunkFromSelf

Signature

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

Added in v1.0.0

Data transformations

data

Signature

export declare const data: <R, I extends unknown, A extends unknown>(item: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

dataFromSelf

Signature

export declare const dataFromSelf: <R, I extends unknown, A extends unknown>(item: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

Date constructors

DateFromSelf

Represents a schema for handling potentially invalid Date instances (e.g., new Date("Invalid Date") is not rejected).

Signature

export declare const DateFromSelf: DateFromSelf

Added in v1.0.0

ValidDateFromSelf

Represents a schema for handling only valid dates. For example, new Date("Invalid Date") is rejected, even though it is an instance of Date.

Signature

export declare const ValidDateFromSelf: ValidDateFromSelf

Added in v1.0.0

Date filters

validDate

A filter that excludes invalid dates (e.g., new Date("Invalid Date") is rejected).

Signature

export declare const validDate: (
  annotations?: Annotations.Filter<Date>
) => <I, R>(self: Schema<Date, I, R>) => Schema<Date, I, R>

Added in v1.0.0

Date transformations

Date

A schema that transforms a string into a valid Date, ensuring that invalid dates, such as new Date("Invalid Date"), are rejected.

Signature

export declare const Date: $Date

Added in v1.0.0

DateFromString

Represents a schema that converts a string into a (potentially invalid) Date (e.g., new Date("Invalid Date") is not rejected).

Signature

export declare const DateFromString: DateFromString

Added in v1.0.0

Duration constructors

DurationFromSelf

Signature

export declare const DurationFromSelf: DurationFromSelf

Added in v1.0.0

Duration filters

betweenDuration

Signature

export declare const betweenDuration: <A extends duration_.Duration>(
  minimum: duration_.DurationInput,
  maximum: duration_.DurationInput,
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

greaterThanDuration

Signature

export declare const greaterThanDuration: <A extends duration_.Duration>(
  min: duration_.DurationInput,
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

greaterThanOrEqualToDuration

Signature

export declare const greaterThanOrEqualToDuration: <A extends duration_.Duration>(
  min: duration_.DurationInput,
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

lessThanDuration

Signature

export declare const lessThanDuration: <A extends duration_.Duration>(
  max: duration_.DurationInput,
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

lessThanOrEqualToDuration

Signature

export declare const lessThanOrEqualToDuration: <A extends duration_.Duration>(
  max: duration_.DurationInput,
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

Duration transformations

Duration

A schema that transforms a [number, number] tuple into a Duration.

Signature

export declare const Duration: Duration

Added in v1.0.0

DurationFromMillis

A schema that transforms a number tuple into a Duration. Treats the value as the number of milliseconds.

Signature

export declare const DurationFromMillis: DurationFromMillis

Added in v1.0.0

DurationFromNanos

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

Signature

export declare const DurationFromNanos: DurationFromNanos

Added in v1.0.0

clampDuration

Clamps a Duration between a minimum and a maximum value.

Signature

export declare const clampDuration: (
  minimum: duration_.DurationInput,
  maximum: duration_.DurationInput
) => <R, I, A extends duration_.Duration>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

Either transformations

either

Signature

export declare const either: <R extends Schema.Any, L extends Schema.Any>({
  left,
  right
}: {
  readonly left: L
  readonly right: R
}) => either<R, L>

Added in v1.0.0

eitherFromSelf

Signature

export declare const eitherFromSelf: <R extends Schema.Any, L extends Schema.Any>({
  left,
  right
}: {
  readonly left: L
  readonly right: R
}) => eitherFromSelf<R, L>

Added in v1.0.0

eitherFromUnion

Signature

export declare const eitherFromUnion: <R extends Schema.Any, L extends Schema.Any>({
  left,
  right
}: {
  readonly left: L
  readonly right: R
}) => eitherFromUnion<R, L>

Example

import * as Schema from "@effect/schema/Schema"

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

Added in v1.0.0

Either utils

EitherEncoded (type alias)

Signature

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

Added in v1.0.0

LeftEncoded (type alias)

Signature

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

Added in v1.0.0

RightEncoded (type alias)

Signature

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

Added in v1.0.0

Encoding transformations

Base64

Signature

export declare const Base64: Schema<Uint8Array, string, never>

Added in v1.0.0

Base64Url

Signature

export declare const Base64Url: Schema<Uint8Array, string, never>

Added in v1.0.0

Hex

Signature

export declare const Hex: Schema<Uint8Array, string, never>

Added in v1.0.0

Exit transformations

exit

Signature

export declare const exit: <A extends Schema.All, E extends Schema.All, DR = never>({
  defect,
  failure,
  success
}: {
  readonly failure: E
  readonly success: A
  readonly defect?: Schema<unknown, unknown, DR> | undefined
}) => exit<A, E, DR>

Added in v1.0.0

exitFromSelf

Signature

export declare const exitFromSelf: <A extends Schema.Any, E extends Schema.Any, DR = never>({
  defect,
  failure,
  success
}: {
  readonly failure: E
  readonly success: A
  readonly defect?: Schema<unknown, unknown, DR> | undefined
}) => exitFromSelf<A, E, DR>

Added in v1.0.0

Exit utils

ExitEncoded (type alias)

Signature

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

Added in v1.0.0

FiberId

FiberIdEncoded (type alias)

Signature

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

Added in v1.0.0

FiberId constructors

FiberIdFromSelf

Signature

export declare const FiberIdFromSelf: FiberIdFromSelf

Added in v1.0.0

FiberId transformations

FiberId

Signature

export declare const FiberId: FiberId

Added in v1.0.0

HashMap transformations

hashMap

Signature

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

Added in v1.0.0

hashMapFromSelf

Signature

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

Added in v1.0.0

HashSet transformations

hashSet

Signature

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

Added in v1.0.0

hashSetFromSelf

Signature

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

Added in v1.0.0

List transformations

list

Signature

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

Added in v1.0.0

listFromSelf

Signature

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

Added in v1.0.0

Map

mapFromSelf

Signature

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

Added in v1.0.0

Map transformations

map

Signature

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

Added in v1.0.0

Option transformations

option

Signature

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

Added in v1.0.0

optionFromNullable

Signature

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

Added in v1.0.0

optionFromNullish

Signature

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

Added in v1.0.0

optionFromOrUndefined

Signature

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

Added in v1.0.0

optionFromSelf

Signature

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

Added in v1.0.0

Option utils

OptionEncoded (type alias)

Signature

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

Added in v1.0.0

PropertySignature

FromPropertySignature (class)

Signature

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

Added in v1.0.0

PropertySignature (interface)

Signature

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

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

Added in v1.0.0

PropertySignatureDeclaration (class)

Signature

export declare class PropertySignatureDeclaration { constructor(
    readonly type: AST.AST,
    readonly isOptional: boolean,
    readonly isReadonly: boolean,
    readonly annotations: AST.Annotations
  ) }

Added in v1.0.0

toString (method)

Signature

toString()

Added in v1.0.0

_tag (property)

Signature

readonly _tag: "PropertySignatureDeclaration"

Added in v1.0.0

PropertySignatureTransformation (class)

Signature

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

Added in v1.0.0

toString (method)

Signature

toString()

Added in v1.0.0

_tag (property)

Signature

readonly _tag: "PropertySignatureTransformation"

Added in v1.0.0

ToPropertySignature (class)

Signature

export declare class ToPropertySignature { constructor(
    readonly type: AST.AST,
    readonly isOptional: boolean,
    readonly isReadonly: boolean,
    readonly annotations: AST.Annotations
  ) }

Added in v1.0.0

fromKey

Signature

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

Added in v1.0.0

optional

Signature

export declare const optional: {
  <
    A,
    const Options extends
      | {
          readonly default?: undefined
          readonly as?: undefined
          readonly exact?: true | undefined
          readonly nullable?: true | undefined
        }
      | {
          readonly default: () => A
          readonly as?: undefined
          readonly exact?: true | undefined
          readonly nullable?: true | undefined
        }
      | {
          readonly as: "Option"
          readonly default?: undefined
          readonly exact?: true | undefined
          readonly nullable?: true | undefined
        }
      | undefined
  >(
    options?: Options | undefined
  ): <I, R>(
    schema: Schema<A, I, R>
  ) => [undefined] extends [Options]
    ? PropertySignature<"?:", A | undefined, never, "?:", I | undefined, R>
    : PropertySignature<":" | "?:", any, never, "?:", I | null | undefined, R>
  <
    A,
    I,
    R,
    const Options extends
      | {
          readonly default?: undefined
          readonly as?: undefined
          readonly exact?: true | undefined
          readonly nullable?: true | undefined
        }
      | {
          readonly default: () => A
          readonly as?: undefined
          readonly exact?: true | undefined
          readonly nullable?: true | undefined
        }
      | {
          readonly as: "Option"
          readonly default?: undefined
          readonly exact?: true | undefined
          readonly nullable?: true | undefined
        }
      | undefined
  >(
    schema: Schema<A, I, R>,
    options?: Options | undefined
  ): [undefined] extends [Options]
    ? PropertySignature<"?:", A | undefined, never, "?:", I | undefined, R>
    : PropertySignature<":" | "?:", any, never, "?:", I | null | undefined, R>
}

Added in v1.0.0

optionalToOptional

  • 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

export 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, FR | TR>

Added in v1.0.0

optionalToRequired

  • 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

export 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, FR | TR>

Added in v1.0.0

propertySignature

Signature

export declare const propertySignature: <A, I, R>(self: Schema<A, I, R>) => PropertySignature<":", A, never, ":", I, R>

Added in v1.0.0

ReadonlyArray filters

itemsCount

Signature

export declare const itemsCount: <A>(
  n: number,
  annotations?: Annotations.Filter<ReadonlyArray<A>> | undefined
) => <I, R>(self: Schema<ReadonlyArray<A>, I, R>) => Schema<ReadonlyArray<A>, I, R>

Added in v1.0.0

maxItems

Signature

export declare const maxItems: <A>(
  n: number,
  annotations?: Annotations.Filter<ReadonlyArray<A>> | undefined
) => <I, R>(self: Schema<ReadonlyArray<A>, I, R>) => Schema<ReadonlyArray<A>, I, R>

Added in v1.0.0

minItems

Signature

export declare const minItems: <A>(
  n: number,
  annotations?: Annotations.Filter<ReadonlyArray<A>> | undefined
) => <I, R>(self: Schema<ReadonlyArray<A>, I, R>) => Schema<ReadonlyArray<A>, I, R>

Added in v1.0.0

ReadonlyArray transformations

getNumberIndexedAccess

Signature

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

Added in v1.0.0

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

Signature

export declare const head: <A, I, R>(self: Schema<ReadonlyArray<A>, I, R>) => Schema<Option.Option<A>, I, R>

Added in v1.0.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

export declare const headOrElse: {
  <A>(fallback?: any): <I, R>(self: Schema<ReadonlyArray<A>, I, R>) => Schema<A, I, R>
  <A, I, R>(self: Schema<ReadonlyArray<A>, I, R>, fallback?: any): Schema<A, I, R>
}

Added in v1.0.0

ReadonlyMap

readonlyMapFromSelf

Signature

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

Added in v1.0.0

ReadonlyMap transformations

readonlyMap

Signature

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

Added in v1.0.0

ReadonlySet

readonlySetFromSelf

Signature

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

Added in v1.0.0

ReadonlySet transformations

readonlySet

Signature

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

Added in v1.0.0

Secret constructors

SecretFromSelf

Signature

export declare const SecretFromSelf: SecretFromSelf

Added in v1.0.0

Secret transformations

Secret

A schema that transforms a string into a Secret.

Signature

export declare const Secret: Secret

Added in v1.0.0

Set

setFromSelf

Signature

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

Added in v1.0.0

Set transformations

set

Signature

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

Added in v1.0.0

SortedSet transformations

sortedSet

Signature

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

Added in v1.0.0

sortedSetFromSelf

Signature

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

Added in v1.0.0

Uint8Array constructors

Uint8ArrayFromSelf

Signature

export declare const Uint8ArrayFromSelf: Schema<Uint8Array, Uint8Array, never>

Added in v1.0.0

Uint8Array transformations

Uint8Array

A schema that transforms a number array into a Uint8Array.

Signature

export declare const Uint8Array: Schema<Uint8Array, ReadonlyArray<number>, never>

Added in v1.0.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.Schema<A>): Self
}

Added in v1.0.0

Annotable (namespace)

Added in v1.0.0

All (type alias)

Signature

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

Added in v1.0.0

Any (type alias)

Signature

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

Added in v1.0.0

Self (type alias)

Signature

export type Self<S extends All> = ReturnType<S["annotations"]>

Added in v1.0.0

Annotations (namespace)

Added in v1.0.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>
}

Added in v1.0.0

Filter (interface)

Signature

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

Added in v1.0.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 typeId?: AST.TypeAnnotation | { id: AST.TypeAnnotation; annotation: unknown }
  readonly jsonSchema?: AST.JSONSchemaAnnotation
  readonly arbitrary?: (
    ...arbitraries: { readonly [K in keyof TypeParameters]: LazyArbitrary<TypeParameters[K]> }
  ) => LazyArbitrary<A>
  readonly pretty?: (
    ...pretties: { readonly [K in keyof TypeParameters]: pretty_.Pretty<TypeParameters[K]> }
  ) => pretty_.Pretty<A>
  readonly equivalence?: (
    ...equivalences: { readonly [K in keyof TypeParameters]: Equivalence.Equivalence<TypeParameters[K]> }
  ) => Equivalence.Equivalence<A>
  readonly concurrency?: AST.ConcurrencyAnnotation
  readonly batching?: AST.BatchingAnnotation
  readonly parseIssueTitle?: AST.ParseIssueTitleAnnotation
}

Added in v1.0.0

annotations

Signature

export declare const annotations: {
  <S extends Annotable.All>(
    annotations: Annotations.Schema<Schema.Type<S>, readonly []>
  ): (self: S) => ReturnType<S["annotations"]>
  <S extends Annotable.All>(
    self: S,
    annotations: Annotations.Schema<Schema.Type<S>, readonly []>
  ): ReturnType<S["annotations"]>
}

Added in v1.0.0

batching

Signature

export declare const batching: (
  batching: AST.BatchingAnnotation
) => <S extends Annotable.All>(self: S) => ReturnType<S["annotations"]>

Added in v1.0.0

concurrency

Signature

export declare const concurrency: (
  concurrency: AST.ConcurrencyAnnotation
) => <S extends Annotable.All>(self: S) => ReturnType<S["annotations"]>

Added in v1.0.0

default

Signature

export declare const default: <S extends Annotable.All>(value: Schema.Type<S>) => (self: S) => ReturnType<S["annotations"]>

Added in v1.0.0

description

Signature

export declare const description: (
  description: AST.DescriptionAnnotation
) => <S extends Annotable.All>(self: S) => ReturnType<S["annotations"]>

Added in v1.0.0

documentation

Signature

export declare const documentation: (
  documentation: AST.DocumentationAnnotation
) => <S extends Annotable.All>(self: S) => ReturnType<S["annotations"]>

Added in v1.0.0

equivalence

Signature

export declare const equivalence: <S extends Annotable.All>(
  equivalence: Equivalence.Equivalence<Schema.Type<S>>
) => (self: S) => ReturnType<S["annotations"]>

Added in v1.0.0

examples

Signature

export declare const examples: <S extends Annotable.All>(
  examples: ReadonlyArray.NonEmptyReadonlyArray<A>
) => (self: S) => ReturnType<S["annotations"]>

Added in v1.0.0

identifier

Signature

export declare const identifier: (
  identifier: AST.IdentifierAnnotation
) => <S extends Annotable.All>(self: S) => ReturnType<S["annotations"]>

Added in v1.0.0

jsonSchema

Attaches a JSON Schema annotation to a schema that represents a refinement.

If the schema is composed of more than one refinement, the corresponding annotations will be merged.

Signature

export declare const jsonSchema: (
  jsonSchema: AST.JSONSchemaAnnotation
) => <S extends Annotable.All>(self: S) => ReturnType<S["annotations"]>

Added in v1.0.0

message

Signature

export declare const message: (
  message: AST.MessageAnnotation
) => <S extends Annotable.All>(self: S) => ReturnType<S["annotations"]>

Added in v1.0.0

parseIssueTitle

Signature

export declare const parseIssueTitle: (
  f: AST.ParseIssueTitleAnnotation
) => <S extends Annotable.All>(self: S) => ReturnType<S["annotations"]>

Added in v1.0.0

title

Signature

export declare const title: (
  title: AST.TitleAnnotation
) => <S extends Annotable.All>(self: S) => ReturnType<S["annotations"]>

Added in v1.0.0

api interface

$Date (interface)

Signature

export interface $Date extends Annotable<$Date, Date, string> {}

Added in v1.0.0

$any (interface)

Signature

export interface $any extends Annotable<$any, any> {}

Added in v1.0.0

$bigint (interface)

Signature

export interface $bigint extends Annotable<$bigint, bigint, string> {}

Added in v1.0.0

$boolean (interface)

Signature

export interface $boolean extends Annotable<$boolean, boolean> {}

Added in v1.0.0

$never (interface)

Signature

export interface $never extends Annotable<$never, never> {}

Added in v1.0.0

$null (interface)

Signature

export interface $null extends Annotable<$null, null> {}

Added in v1.0.0

$number (interface)

Signature

export interface $number extends Annotable<$number, number> {}

Added in v1.0.0

$object (interface)

Signature

export interface $object extends Annotable<$object, object> {}

Added in v1.0.0

$string (interface)

Signature

export interface $string extends Annotable<$string, string> {}

Added in v1.0.0

$symbol (interface)

Signature

export interface $symbol extends Annotable<$symbol, symbol, string> {}

Added in v1.0.0

$undefined (interface)

Signature

export interface $undefined extends Annotable<$undefined, undefined> {}

Added in v1.0.0

$unknown (interface)

Signature

export interface $unknown extends Annotable<$unknown, unknown> {}

Added in v1.0.0

$void (interface)

Signature

export interface $void extends Annotable<$void, void> {}

Added in v1.0.0

BigDecimal (interface)

Signature

export interface BigDecimal extends Annotable<BigDecimal, bigDecimal_.BigDecimal, string> {}

Added in v1.0.0

BigDecimalFromNumber (interface)

Signature

export interface BigDecimalFromNumber extends Annotable<BigDecimalFromNumber, bigDecimal_.BigDecimal, number> {}

Added in v1.0.0

BigDecimalFromSelf (interface)

Signature

export interface BigDecimalFromSelf extends Annotable<BigDecimalFromSelf, bigDecimal_.BigDecimal> {}

Added in v1.0.0

BigintFromNumber (interface)

Signature

export interface BigintFromNumber extends Annotable<BigintFromNumber, bigint, number> {}

Added in v1.0.0

BooleanFromUnknown (interface)

Signature

export interface BooleanFromUnknown extends Annotable<BooleanFromUnknown, boolean, unknown> {}

Added in v1.0.0

Class (interface)

Signature

export interface Class<Self, Fields extends Struct.Fields, A, I, R, C, Inherited, Proto> extends Schema<Self, I, R> {
  new (
    props: keyof C extends never ? void | {} : C,
    disableValidation?: boolean | undefined
  ): A & Omit<Inherited, keyof A> & Proto

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

  readonly identifier: string

  readonly extend: <Extended = never>(
    identifier: string
  ) => <newFields extends Struct.Fields>(
    fields: newFields,
    annotations?: Annotations.Schema<Extended>
  ) => [Extended] extends [never]
    ? MissingSelfGeneric<"Base.extend">
    : Class<
        Extended,
        Fields & newFields,
        Types.Simplify<A & Struct.Type<newFields>>,
        Types.Simplify<I & Struct.Encoded<newFields>>,
        R | Struct.Context<newFields>,
        Types.Simplify<C & Struct.Type<newFields>>,
        Self,
        Proto
      >

  readonly transformOrFail: <Transformed = never>(
    identifier: string
  ) => <newFields extends Struct.Fields, R2, R3>(
    fields: newFields,
    options: {
      readonly decode: (
        input: A,
        options: ParseOptions,
        ast: AST.Transformation
      ) => Effect.Effect<Types.Simplify<A & Struct.Type<newFields>>, ParseResult.ParseIssue, R2>
      readonly encode: (
        input: Types.Simplify<A & Struct.Type<newFields>>,
        options: ParseOptions,
        ast: AST.Transformation
      ) => Effect.Effect<A, ParseResult.ParseIssue, R3>
    }
  ) => [Transformed] extends [never]
    ? MissingSelfGeneric<"Base.transform">
    : Class<
        Transformed,
        Fields & newFields,
        Types.Simplify<A & Struct.Type<newFields>>,
        I,
        R | Struct.Context<newFields> | R2 | R3,
        Types.Simplify<C & Struct.Type<newFields>>,
        Self,
        Proto
      >

  readonly transformOrFailFrom: <Transformed = never>(
    identifier: string
  ) => <newFields extends Struct.Fields, R2, R3>(
    fields: newFields,
    options: {
      readonly decode: (
        input: I,
        options: ParseOptions,
        ast: AST.Transformation
      ) => Effect.Effect<Types.Simplify<I & Struct.Encoded<newFields>>, ParseResult.ParseIssue, R2>
      readonly encode: (
        input: Types.Simplify<I & Struct.Encoded<newFields>>,
        options: ParseOptions,
        ast: AST.Transformation
      ) => Effect.Effect<I, ParseResult.ParseIssue, R3>
    }
  ) => [Transformed] extends [never]
    ? MissingSelfGeneric<"Base.transformFrom">
    : Class<
        Transformed,
        Fields & newFields,
        Types.Simplify<A & Struct.Type<newFields>>,
        I,
        R | Struct.Context<newFields> | R2 | R3,
        Types.Simplify<C & Struct.Type<newFields>>,
        Self,
        Proto
      >
}

Added in v1.0.0

DateFromSelf (interface)

Signature

export interface DateFromSelf extends Annotable<DateFromSelf, Date> {}

Added in v1.0.0

DateFromString (interface)

Signature

export interface DateFromString extends Annotable<DateFromString, Date, string> {}

Added in v1.0.0

Duration (interface)

Signature

export interface Duration extends Annotable<Duration, duration_.Duration, readonly [seconds: number, nanos: number]> {}

Added in v1.0.0

DurationFromMillis (interface)

Signature

export interface DurationFromMillis extends Annotable<DurationFromMillis, duration_.Duration, number> {}

Added in v1.0.0

DurationFromNanos (interface)

Signature

export interface DurationFromNanos extends Annotable<DurationFromNanos, duration_.Duration, bigint> {}

Added in v1.0.0

DurationFromSelf (interface)

Signature

export interface DurationFromSelf extends Annotable<DurationFromSelf, duration_.Duration> {}

Added in v1.0.0

FiberId (interface)

Signature

export interface FiberId extends Annotable<FiberId, fiberId_.FiberId, FiberIdEncoded> {}

Added in v1.0.0

FiberIdFromSelf (interface)

Signature

export interface FiberIdFromSelf extends Annotable<FiberIdFromSelf, fiberId_.FiberId> {}

Added in v1.0.0

Lowercase (interface)

Signature

export interface Lowercase extends Annotable<Lowercase, string> {}

Added in v1.0.0

Not (interface)

Signature

export interface Not extends Annotable<Not, boolean> {}

Added in v1.0.0

NumberFromString (interface)

Signature

export interface NumberFromString extends Annotable<NumberFromString, number, string> {}

Added in v1.0.0

Secret (interface)

Signature

export interface Secret extends Annotable<Secret, secret_.Secret, string> {}

Added in v1.0.0

SecretFromSelf (interface)

Signature

export interface SecretFromSelf extends Annotable<SecretFromSelf, secret_.Secret> {}

Added in v1.0.0

Trim (interface)

Signature

export interface Trim extends Annotable<Trim, string> {}

Added in v1.0.0

Uppercase (interface)

Signature

export interface Uppercase extends Annotable<Uppercase, string> {}

Added in v1.0.0

ValidDateFromSelf (interface)

Signature

export interface ValidDateFromSelf extends Annotable<ValidDateFromSelf, Date> {}

Added in v1.0.0

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

Added in v1.0.0

bigintFromSelf (interface)

Signature

export interface bigintFromSelf extends Annotable<bigintFromSelf, bigint> {}

Added in v1.0.0

brand (interface)

Signature

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

Added in v1.0.0

cause (interface)

Signature

export interface cause<E extends Schema.All, DR>
  extends Annotable<
    cause<E, DR>,
    Cause.Cause<Schema.Type<E>>,
    CauseEncoded<Schema.Encoded<E>>,
    Schema.Context<E> | DR
  > {}

Added in v1.0.0

causeFromSelf (interface)

Signature

export interface causeFromSelf<E extends Schema.Any, DR>
  extends Annotable<
    causeFromSelf<E, DR>,
    Cause.Cause<Schema.Type<E>>,
    Cause.Cause<Schema.Encoded<E>>,
    Schema.Context<E> | DR
  > {}

Added in v1.0.0

chunk (interface)

Signature

export interface chunk<Value extends Schema.Any>
  extends Annotable<
    chunk<Value>,
    Chunk.Chunk<Schema.Type<Value>>,
    ReadonlyArray<Schema.Encoded<Value>>,
    Schema.Context<Value>
  > {}

Added in v1.0.0

chunkFromSelf (interface)

Signature

export interface chunkFromSelf<Value extends Schema.Any>
  extends Annotable<
    chunkFromSelf<Value>,
    Chunk.Chunk<Schema.Type<Value>>,
    Chunk.Chunk<Schema.Encoded<Value>>,
    Schema.Context<Value>
  > {}

Added in v1.0.0

either (interface)

Signature

export interface either<R extends Schema.Any, L extends Schema.Any>
  extends Annotable<
    either<R, L>,
    Either.Either<Schema.Type<R>, Schema.Type<L>>,
    EitherEncoded<Schema.Encoded<R>, Schema.Encoded<L>>,
    Schema.Context<R> | Schema.Context<L>
  > {}

Added in v1.0.0

eitherFromSelf (interface)

Signature

export interface eitherFromSelf<R extends Schema.Any, L extends Schema.Any>
  extends Annotable<
    eitherFromSelf<R, L>,
    Either.Either<Schema.Type<R>, Schema.Type<L>>,
    Either.Either<Schema.Encoded<R>, Schema.Encoded<L>>,
    Schema.Context<R> | Schema.Context<L>
  > {}

Added in v1.0.0

eitherFromUnion (interface)

Signature

export interface eitherFromUnion<R extends Schema.Any, L extends Schema.Any>
  extends Annotable<
    eitherFromUnion<R, L>,
    Either.Either<Schema.Type<R>, Schema.Type<L>>,
    Schema.Encoded<R> | Schema.Encoded<L>,
    Schema.Context<R> | Schema.Context<L>
  > {}

Added in v1.0.0

enums (interface)

Signature

export interface enums<A extends { [x: string]: string | number }> extends Annotable<enums<A>, A[keyof A]> {
  readonly enums: A
}

Added in v1.0.0

exit (interface)

Signature

export interface exit<A extends Schema.All, E extends Schema.All, DR>
  extends Annotable<
    exit<A, E, DR>,
    Exit.Exit<Schema.Type<A>, Schema.Type<E>>,
    ExitEncoded<Schema.Encoded<A>, Schema.Encoded<E>>,
    Schema.Context<A> | Schema.Context<E> | DR
  > {}

Added in v1.0.0

exitFromSelf (interface)

Signature

export interface exitFromSelf<A extends Schema.Any, E extends Schema.Any, DR>
  extends Annotable<
    exitFromSelf<A, E, DR>,
    Exit.Exit<Schema.Type<A>, Schema.Type<E>>,
    Exit.Exit<Schema.Encoded<A>, Schema.Encoded<E>>,
    Schema.Context<A> | Schema.Context<E> | DR
  > {}

Added in v1.0.0

extend (interface)

Signature

export interface extend<Self extends Schema.Any, That extends Schema.Any>
  extends Schema<
    Types.Simplify<Schema.Type<Self> & Schema.Type<That>>,
    Types.Simplify<Schema.Encoded<Self> & Schema.Encoded<That>>,
    Schema.Context<Self> | Schema.Context<That>
  > {}

Added in v1.0.0

hashMap (interface)

Signature

export interface hashMap<K extends Schema.Any, V extends Schema.Any>
  extends Annotable<
    hashMap<K, V>,
    HashMap.HashMap<Schema.Type<K>, Schema.Type<V>>,
    ReadonlyArray<readonly [Schema.Encoded<K>, Schema.Encoded<V>]>,
    Schema.Context<K> | Schema.Context<V>
  > {}

Added in v1.0.0

hashMapFromSelf (interface)

Signature

export interface hashMapFromSelf<K extends Schema.Any, V extends Schema.Any>
  extends Annotable<
    hashMapFromSelf<K, V>,
    HashMap.HashMap<Schema.Type<K>, Schema.Type<V>>,
    HashMap.HashMap<Schema.Encoded<K>, Schema.Encoded<V>>,
    Schema.Context<K> | Schema.Context<V>
  > {}

Added in v1.0.0

hashSet (interface)

Signature

export interface hashSet<Value extends Schema.Any>
  extends Annotable<
    hashSet<Value>,
    HashSet.HashSet<Schema.Type<Value>>,
    ReadonlyArray<Schema.Encoded<Value>>,
    Schema.Context<Value>
  > {}

Added in v1.0.0

hashSetFromSelf (interface)

Signature

export interface hashSetFromSelf<Value extends Schema.Any>
  extends Annotable<
    hashSetFromSelf<Value>,
    HashSet.HashSet<Schema.Type<Value>>,
    HashSet.HashSet<Schema.Encoded<Value>>,
    Schema.Context<Value>
  > {}

Added in v1.0.0

instanceOf (interface)

Signature

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

Added in v1.0.0

list (interface)

Signature

export interface list<Value extends Schema.Any>
  extends Annotable<
    list<Value>,
    List.List<Schema.Type<Value>>,
    ReadonlyArray<Schema.Encoded<Value>>,
    Schema.Context<Value>
  > {}

Added in v1.0.0

listFromSelf (interface)

Signature

export interface listFromSelf<Value extends Schema.Any>
  extends Annotable<
    listFromSelf<Value>,
    List.List<Schema.Type<Value>>,
    List.List<Schema.Encoded<Value>>,
    Schema.Context<Value>
  > {}

Added in v1.0.0

literal (interface)

Signature

export interface literal<Literals extends ReadonlyArray.NonEmptyReadonlyArray<AST.LiteralValue>>
  extends Annotable<literal<Literals>, Literals[number]> {
  readonly literals: Readonly<Literals>
}

Added in v1.0.0

map (interface)

Signature

export interface map<K extends Schema.Any, V extends Schema.Any>
  extends Annotable<
    map<K, V>,
    Map<Schema.Type<K>, Schema.Type<V>>,
    ReadonlyArray<readonly [Schema.Encoded<K>, Schema.Encoded<V>]>,
    Schema.Context<K> | Schema.Context<V>
  > {}

Added in v1.0.0

mapFromSelf (interface)

Signature

export interface mapFromSelf<K extends Schema.Any, V extends Schema.Any>
  extends Annotable<
    mapFromSelf<K, V>,
    Map<Schema.Type<K>, Schema.Type<V>>,
    ReadonlyMap<Schema.Encoded<K>, Schema.Encoded<V>>,
    Schema.Context<K> | Schema.Context<V>
  > {}

Added in v1.0.0

mutable (interface)

Signature

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

Added in v1.0.0

nonEmptyArray (interface)

Signature

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

Added in v1.0.0

nullable (interface)

Signature

export interface nullable<S extends Schema.Any> extends union<[S, $null]> {
  annotations(annotations: Annotations.Schema<Schema.Type<S> | null>): nullable<S>
}

Added in v1.0.0

nullish (interface)

Signature

export interface nullish<S extends Schema.Any> extends union<[S, $null, $undefined]> {
  annotations(annotations: Annotations.Schema<Schema.Type<S> | null | undefined>): nullish<S>
}

Added in v1.0.0

option (interface)

Signature

export interface option<Value extends Schema.Any>
  extends Annotable<
    option<Value>,
    Option.Option<Schema.Type<Value>>,
    OptionEncoded<Schema.Encoded<Value>>,
    Schema.Context<Value>
  > {}

Added in v1.0.0

optionFromNullable (interface)

Signature

export interface optionFromNullable<Value extends Schema.Any>
  extends Annotable<
    optionFromNullable<Value>,
    Option.Option<Schema.Type<Value>>,
    Schema.Encoded<Value> | null,
    Schema.Context<Value>
  > {}

Added in v1.0.0

optionFromNullish (interface)

Signature

export interface optionFromNullish<Value extends Schema.Any>
  extends Annotable<
    optionFromNullish<Value>,
    Option.Option<Schema.Type<Value>>,
    Schema.Encoded<Value> | null | undefined,
    Schema.Context<Value>
  > {}

Added in v1.0.0

optionFromOrUndefined (interface)

Signature

export interface optionFromOrUndefined<Value extends Schema.Any>
  extends Annotable<
    optionFromOrUndefined<Value>,
    Option.Option<Schema.Type<Value>>,
    Schema.Encoded<Value> | undefined,
    Schema.Context<Value>
  > {}

Added in v1.0.0

optionFromSelf (interface)

Signature

export interface optionFromSelf<Value extends Schema.Any>
  extends Annotable<
    optionFromSelf<Value>,
    Option.Option<Schema.Type<Value>>,
    Option.Option<Schema.Encoded<Value>>,
    Schema.Context<Value>
  > {}

Added in v1.0.0

orUndefined (interface)

Signature

export interface orUndefined<S extends Schema.Any> extends union<[S, $undefined]> {
  annotations(annotations: Annotations.Schema<Schema.Type<S> | undefined>): orUndefined<S>
}

Added in v1.0.0

readonlyMap (interface)

Signature

export interface readonlyMap<K extends Schema.Any, V extends Schema.Any>
  extends Annotable<
    readonlyMap<K, V>,
    ReadonlyMap<Schema.Type<K>, Schema.Type<V>>,
    ReadonlyArray<readonly [Schema.Encoded<K>, Schema.Encoded<V>]>,
    Schema.Context<K> | Schema.Context<V>
  > {}

Added in v1.0.0

readonlyMapFromSelf (interface)

Signature

export interface readonlyMapFromSelf<K extends Schema.Any, V extends Schema.Any>
  extends Annotable<
    readonlyMapFromSelf<K, V>,
    ReadonlyMap<Schema.Type<K>, Schema.Type<V>>,
    ReadonlyMap<Schema.Encoded<K>, Schema.Encoded<V>>,
    Schema.Context<K> | Schema.Context<V>
  > {}

Added in v1.0.0

readonlySet (interface)

Signature

export interface readonlySet<Value extends Schema.Any>
  extends Annotable<
    readonlySet<Value>,
    ReadonlySet<Schema.Type<Value>>,
    ReadonlyArray<Schema.Encoded<Value>>,
    Schema.Context<Value>
  > {}

Added in v1.0.0

readonlySetFromSelf (interface)

Signature

export interface readonlySetFromSelf<Value extends Schema.Any>
  extends Annotable<
    readonlySetFromSelf<Value>,
    ReadonlySet<Schema.Type<Value>>,
    ReadonlySet<Schema.Encoded<Value>>,
    Schema.Context<Value>
  > {}

Added in v1.0.0

record (interface)

Signature

export interface record<K extends Schema.All, V extends Schema.All> extends typeLiteral<{}, [{ key: K; value: V }]> {
  readonly key: K
  readonly value: V
  annotations(annotations: Annotations.Schema<Simplify<TypeLiteral.Type<{}, [{ key: K; value: V }]>>>): record<K, V>
}

Added in v1.0.0

set (interface)

Signature

export interface set<Value extends Schema.Any>
  extends Annotable<set<Value>, Set<Schema.Type<Value>>, ReadonlyArray<Schema.Encoded<Value>>, Schema.Context<Value>> {}

Added in v1.0.0

setFromSelf (interface)

Signature

export interface setFromSelf<Value extends Schema.Any>
  extends Annotable<
    setFromSelf<Value>,
    Set<Schema.Type<Value>>,
    ReadonlySet<Schema.Encoded<Value>>,
    Schema.Context<Value>
  > {}

Added in v1.0.0

sortedSet (interface)

Signature

export interface sortedSet<Value extends Schema.Any>
  extends Annotable<
    sortedSet<Value>,
    SortedSet.SortedSet<Schema.Type<Value>>,
    ReadonlyArray<Schema.Encoded<Value>>,
    Schema.Context<Value>
  > {}

Added in v1.0.0

sortedSetFromSelf (interface)

Signature

export interface sortedSetFromSelf<Value extends Schema.Any>
  extends Annotable<
    sortedSetFromSelf<Value>,
    SortedSet.SortedSet<Schema.Type<Value>>,
    SortedSet.SortedSet<Schema.Encoded<Value>>,
    Schema.Context<Value>
  > {}

Added in v1.0.0

struct (interface)

Signature

export interface struct<Fields extends Struct.Fields> extends typeLiteral<Fields, []> {
  annotations(annotations: Annotations.Schema<Simplify<Struct.Type<Fields>>>): struct<Fields>
}

Added in v1.0.0

suspend (interface)

Signature

export interface suspend<A, I, R> extends Schema<A, I, R> {
  annotations(annotations: Annotations.Schema<A>): suspend<A, I, R>
}

Added in v1.0.0

symbolFromSelf (interface)

Signature

export interface symbolFromSelf extends Annotable<symbolFromSelf, symbol> {}

Added in v1.0.0

transform (interface)

Signature

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

Added in v1.0.0

transformLiteral (interface)

Signature

export interface transformLiteral<Type, Encoded> extends Annotable<transformLiteral<Type, Encoded>, Type, Encoded> {}

Added in v1.0.0

transformOrFail (interface)

Signature

export interface transformOrFail<From extends Schema.Any, To extends Schema.Any, R>
  extends Annotable<
    transformOrFail<From, To, R>,
    Schema.Type<To>,
    Schema.Encoded<From>,
    Schema.Context<From> | Schema.Context<To> | R
  > {
  readonly from: From
  readonly to: To
}

Added in v1.0.0

tuple (interface)

Signature

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

Added in v1.0.0

tupleType (interface)

Signature

export interface tupleType<Elements extends TupleType.Elements, Rest extends ReadonlyArray<Schema.Any>>
  extends Schema<
    TupleType.Type<Elements, Rest>,
    TupleType.Encoded<Elements, Rest>,
    Schema.Context<Elements[number]> | Schema.Context<Rest[number]>
  > {
  readonly elements: Readonly<Elements>
  readonly rest: Readonly<Rest>
  annotations(annotations: Annotations.Schema<TupleType.Type<Elements, Rest>>): tupleType<Elements, Rest>
}

Added in v1.0.0

typeLiteral (interface)

Signature

export interface typeLiteral<Fields extends Struct.Fields, Records extends IndexSignature.Records>
  extends Schema<
    Simplify<TypeLiteral.Type<Fields, Records>>,
    Simplify<TypeLiteral.Encoded<Fields, Records>>,
    Struct.Context<Fields> | IndexSignature.Context<Records>
  > {
  readonly fields: { readonly [K in keyof Fields]: Fields[K] }
  readonly records: Readonly<Records>
  annotations(
    annotations: Annotations.Schema<Simplify<TypeLiteral.Type<Fields, Records>>>
  ): typeLiteral<Fields, Records>
}

Added in v1.0.0

union (interface)

Signature

export interface union<Members extends ReadonlyArray<Schema.Any>>
  extends Schema<Schema.Type<Members[number]>, Schema.Encoded<Members[number]>, Schema.Context<Members[number]>> {
  readonly members: Readonly<Members>
  annotations(annotations: Annotations.Schema<Schema.Type<Members[number]>>): union<Members>
}

Added in v1.0.0

bigint constructors

NegativeBigint

Signature

export declare const NegativeBigint: Schema<bigint, string, never>

Added in v1.0.0

NegativeBigintFromSelf

Signature

export declare const NegativeBigintFromSelf: Schema<bigint, bigint, never>

Added in v1.0.0

NonNegativeBigint

Signature

export declare const NonNegativeBigint: Schema<bigint, string, never>

Added in v1.0.0

NonNegativeBigintFromSelf

Signature

export declare const NonNegativeBigintFromSelf: Schema<bigint, bigint, never>

Added in v1.0.0

NonPositiveBigint

Signature

export declare const NonPositiveBigint: Schema<bigint, string, never>

Added in v1.0.0

NonPositiveBigintFromSelf

Signature

export declare const NonPositiveBigintFromSelf: Schema<bigint, bigint, never>

Added in v1.0.0

PositiveBigint

Signature

export declare const PositiveBigint: Schema<bigint, string, never>

Added in v1.0.0

PositiveBigintFromSelf

Signature

export declare const PositiveBigintFromSelf: Schema<bigint, bigint, never>

Added in v1.0.0

bigint filters

betweenBigint

Signature

export declare const betweenBigint: <A extends bigint>(
  min: bigint,
  max: bigint,
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

greaterThanBigint

Signature

export declare const greaterThanBigint: <A extends bigint>(
  min: bigint,
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

greaterThanOrEqualToBigint

Signature

export declare const greaterThanOrEqualToBigint: <A extends bigint>(
  min: bigint,
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

lessThanBigint

Signature

export declare const lessThanBigint: <A extends bigint>(
  max: bigint,
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

lessThanOrEqualToBigint

Signature

export declare const lessThanOrEqualToBigint: <A extends bigint>(
  max: bigint,
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

negativeBigint

Signature

export declare const negativeBigint: <A extends bigint>(
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

nonNegativeBigint

Signature

export declare const nonNegativeBigint: <A extends bigint>(
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

nonPositiveBigint

Signature

export declare const nonPositiveBigint: <A extends bigint>(
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

positiveBigint

Signature

export declare const positiveBigint: <A extends bigint>(
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

bigint transformations

BigintFromNumber

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

export declare const BigintFromNumber: BigintFromNumber

Added in v1.0.0

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

export declare const bigint: $bigint

Added in v1.0.0

clampBigint

Clamps a bigint between a minimum and a maximum value.

Signature

export declare const clampBigint: (
  minimum: bigint,
  maximum: bigint
) => <R, I, A extends bigint>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

boolean constructors

BooleanFromUnknown

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

Signature

export declare const BooleanFromUnknown: BooleanFromUnknown

Added in v1.0.0

boolean transformations

Not

Signature

export declare const Not: Not

Added in v1.0.0

branding

BrandSchema (interface)

Signature

export interface BrandSchema<A extends Brand.Brand<any>, I>
  extends Annotable<BrandSchema<A, I>, A, I>,
    Brand.Brand.Constructor<A> {}

Added in v1.0.0

asBrandSchema

Signature

export declare const asBrandSchema: <A extends Brand.Brand<any>, I>(schema: BrandSchema<A, I>) => BrandSchema<A, I>

Added in v1.0.0

brand

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

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

Signature

export declare const brand: <S extends Schema.AnyNoContext, B extends string | symbol>(
  brand: B,
  annotations?: Annotations.Schema<any, readonly []> | undefined
) => (self: S) => brand<S, B>

Example

import * as Schema from "@effect/schema/Schema"

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

Added in v1.0.0

classes

Class

Signature

export declare const Class: <Self = never>(
  identifier: string
) => <Fields extends Struct.Fields>(
  fields: Fields,
  annotations?: Annotations.Schema<Self, readonly []> | undefined
) => [Self] extends [never]
  ? "Missing `Self` generic - use `class Self extends Class<Self>()({ ... })`"
  : Class<
      Self,
      Fields,
      Types.Simplify<
        Types.UnionToIntersection<
          {
            [K in keyof F]: F[K] extends Struct.OptionalPropertySignature
              ? { readonly [H in K]?: Schema.Type<F[H]> | undefined }
              : { readonly [h in K]: Schema.Type<F[h]> }
          }[keyof F]
        >
      >,
      Types.Simplify<Struct.Encoded<Fields>>,
      Schema.Context<Fields[keyof Fields]>,
      Types.Simplify<
        Types.UnionToIntersection<
          {
            [K in keyof F]: F[K] extends Struct.OptionalPropertySignature
              ? { readonly [H in K]?: Schema.Type<F[H]> | undefined }
              : { readonly [h in K]: Schema.Type<F[h]> }
          }[keyof F]
        >
      >,
      {},
      {}
    >

Added in v1.0.0

TaggedClass

Signature

export declare const TaggedClass: <Self = never>(
  identifier?: string
) => <Tag extends string, Fields extends Struct.Fields>(
  tag: Tag,
  fields: Fields,
  annotations?: Annotations.Schema<Self, readonly []> | undefined
) => [Self] extends [never]
  ? 'Missing `Self` generic - use `class Self extends TaggedClass<Self>()("Tag", { ... })`'
  : Class<
      Self,
      { readonly _tag: literal<[Tag]> } & Fields,
      Types.Simplify<any>,
      Types.Simplify<
        { readonly _tag: Tag } & {
          readonly [K in Exclude<keyof Fields, Struct.EncodedTokenKeys<Fields>> as Struct.Key<
            Fields,
            K
          >]: Schema.Encoded<Fields[K]>
        } & {
          readonly [K in Struct.EncodedTokenKeys<Fields> as Struct.Key<Fields, K>]?:
            | Schema.Encoded<Fields[K]>
            | undefined
        }
      >,
      Schema.Context<Fields[keyof Fields]>,
      Types.Simplify<
        Types.UnionToIntersection<
          {
            [K in keyof F]: F[K] extends Struct.OptionalPropertySignature
              ? { readonly [H in K]?: Schema.Type<F[H]> | undefined }
              : { readonly [h in K]: Schema.Type<F[h]> }
          }[keyof F]
        >
      >,
      {},
      {}
    >

Added in v1.0.0

TaggedError

Signature

export declare const TaggedError: <Self = never>(
  identifier?: string
) => <Tag extends string, Fields extends Struct.Fields>(
  tag: Tag,
  fields: Fields,
  annotations?: Annotations.Schema<Self, readonly []> | undefined
) => [Self] extends [never]
  ? 'Missing `Self` generic - use `class Self extends TaggedError<Self>()("Tag", { ... })`'
  : Class<
      Self,
      { readonly _tag: literal<[Tag]> } & Fields,
      Types.Simplify<any>,
      Types.Simplify<
        { readonly _tag: Tag } & {
          readonly [K in Exclude<keyof Fields, Struct.EncodedTokenKeys<Fields>> as Struct.Key<
            Fields,
            K
          >]: Schema.Encoded<Fields[K]>
        } & {
          readonly [K in Struct.EncodedTokenKeys<Fields> as Struct.Key<Fields, K>]?:
            | Schema.Encoded<Fields[K]>
            | undefined
        }
      >,
      Schema.Context<Fields[keyof Fields]>,
      Types.Simplify<
        Types.UnionToIntersection<
          {
            [K in keyof F]: F[K] extends Struct.OptionalPropertySignature
              ? { readonly [H in K]?: Schema.Type<F[H]> | undefined }
              : { readonly [h in K]: Schema.Type<F[h]> }
          }[keyof F]
        >
      >,
      {},
      Cause.YieldableError
    >

Added in v1.0.0

TaggedRequest

Signature

export declare const TaggedRequest: <Self = never>(
  identifier?: string
) => <Tag extends string, Fields extends Struct.Fields, EA, EI, ER, AA, AI, AR>(
  tag: Tag,
  Failure: Schema<EA, EI, ER>,
  Success: Schema<AA, AI, AR>,
  fields: Fields,
  annotations?: Annotations.Schema<Self, readonly []> | undefined
) => [Self] extends [never]
  ? 'Missing `Self` generic - use `class Self extends TaggedRequest<Self>()("Tag", SuccessSchema, FailureSchema, { ... })`'
  : Class<
      Self,
      { readonly _tag: literal<[Tag]> } & Fields,
      Types.Simplify<any>,
      Types.Simplify<
        { readonly _tag: Tag } & {
          readonly [K in Exclude<keyof Fields, Struct.EncodedTokenKeys<Fields>> as Struct.Key<
            Fields,
            K
          >]: Schema.Encoded<Fields[K]>
        } & {
          readonly [K in Struct.EncodedTokenKeys<Fields> as Struct.Key<Fields, K>]?:
            | Schema.Encoded<Fields[K]>
            | undefined
        }
      >,
      Schema.Context<Fields[keyof Fields]>,
      Types.Simplify<
        Types.UnionToIntersection<
          {
            [K in keyof F]: F[K] extends Struct.OptionalPropertySignature
              ? { readonly [H in K]?: Schema.Type<F[H]> | undefined }
              : { readonly [h in K]: Schema.Type<F[h]> }
          }[keyof F]
        >
      >,
      TaggedRequest<
        Tag,
        Self,
        { readonly _tag: Tag } & {
          readonly [K in Exclude<keyof Fields, Struct.EncodedTokenKeys<Fields>> as Struct.Key<
            Fields,
            K
          >]: Schema.Encoded<Fields[K]>
        } & {
          readonly [K in Struct.EncodedTokenKeys<Fields> as Struct.Key<Fields, K>]?:
            | Schema.Encoded<Fields[K]>
            | undefined
        },
        Schema.Context<Fields[keyof Fields]>,
        AA,
        AI,
        EA,
        EI,
        ER | AR
      >,
      {}
    >

Added in v1.0.0

TaggedRequest (interface)

Signature

export interface TaggedRequest<Tag extends string, S, SI, SR, A, AI, E, EI, RR>
  extends Request.Request<A, E>,
    Serializable.SerializableWithResult<S, SI, SR, A, AI, E, EI, RR> {
  readonly _tag: Tag
}

Added in v1.0.0

TaggedRequest (namespace)

Added in v1.0.0

Any (type alias)

Signature

export type Any =
  | TaggedRequest<string, any, any, any, any, any, any, any, any>
  | TaggedRequest<string, any, any, any, any, any, never, never, any>

Added in v1.0.0

combinators

array

Signature

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

Added in v1.0.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.

Signature

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

Example

import * as S from "@effect/schema/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
})

Added in v1.0.0

compose

Signature

export declare const compose: {
  <C, B, R2>(to: Schema<C, B, R2>): <A, R1>(from: Schema<B, A, R1>) => Schema<C, A, R2 | R1>
  <D, C, R2>(
    to: Schema<D, C, R2>,
    options: { strict: false }
  ): <B, A, R1>(from: Schema<B, A, R1>) => Schema<D, A, R2 | R1>
  <B, A, R1, C, R2>(from: Schema<B, A, R1>, to: Schema<C, B, R2>): Schema<C, A, R1 | R2>
  <A, B, R1, D, C, R2>(from: Schema<B, A, R1>, to: Schema<D, C, R2>, options: { strict: false }): Schema<D, A, R1 | R2>
}

Added in v1.0.0

extend

Signature

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

Added in v1.0.0

filter

Signature

export declare function filter<A>(
  f: (a: A, options: ParseOptions, self: AST.Refinement) => Option.Option<ParseResult.ParseIssue>,
  annotations?: Annotations.Filter<A>
): <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>
export declare function filter<C extends A, B extends A, A = C>(
  refinement: Predicate.Refinement<A, B>,
  annotations?: Annotations.Filter<A>
): <I, R>(self: Schema<C, I, R>) => Schema<C & B, I, R>
export declare function filter<A>(
  predicate: Predicate.Predicate<Types.NoInfer<A>>,
  annotations?: Annotations.Filter<Types.NoInfer<A>>
): <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

keyof

Signature

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

Added in v1.0.0

mutable

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

Signature

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

Added in v1.0.0

nonEmptyArray

Signature

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

Added in v1.0.0

nullable

Signature

export declare const nullable: <S extends Schema.Any>(self: S) => nullable<S>

Added in v1.0.0

nullish

Signature

export declare const nullish: <S extends Schema.Any>(self: S) => nullish<S>

Added in v1.0.0

orUndefined

Signature

export declare const orUndefined: <S extends Schema.Any>(self: S) => orUndefined<S>

Added in v1.0.0

partial

Signature

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

Added in v1.0.0

record

Signature

export declare const record: <K extends Schema.All, V extends Schema.All>(key: K, value: V) => record<K, V>

Added in v1.0.0

required

Signature

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

Added in v1.0.0

struct

Signature

export declare function struct<Fields extends Struct.Fields, const Records extends IndexSignature.NonEmptyRecords>(
  fields: Fields,
  ...records: Records
): typeLiteral<Fields, Records>
export declare function struct<Fields extends Struct.Fields>(fields: Fields): struct<Fields>

Added in v1.0.0

suspend

Signature

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

Added in v1.0.0

transform

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

Signature

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

Added in v1.0.0

transformOrFail

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

Signature

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

Added in v1.0.0

tuple

Signature

export declare function tuple<
  const Elements extends TupleType.Elements,
  Rest extends ReadonlyArray.NonEmptyReadonlyArray<Schema.Any>
>(elements: Elements, ...rest: Rest): tupleType<Elements, Rest>
export declare function tuple<Elements extends TupleType.Elements>(...elements: Elements): tuple<Elements>

Added in v1.0.0

union

Signature

export declare function union<Members extends AST.Members<Schema.Any>>(...members: Members): union<Members>
export declare function union<Member extends Schema.Any>(member: Member): Member
export declare function union(): $never
export declare function union<Members extends ReadonlyArray<Schema.Any>>(
  ...members: Members
): Schema<Schema.Type<Members[number]>, Schema.Encoded<Members[number]>, Schema.Context<Members[number]>>

Added in v1.0.0

constructors

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

export declare const declare: {
  <A>(
    is: (input: unknown) => input is A,
    annotations?: Annotations.Schema<A, readonly []> | undefined
  ): Schema<A, A, never>
  <const P extends ReadonlyArray<Schema.Any>, I, A>(
    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]> }> | undefined
  ): Schema<A, I, Schema.Context<P[number]>>
}

Added in v1.0.0

enums

Signature

export declare const enums: <A extends { [x: string]: string | number }>(enums: A) => enums<A>

Added in v1.0.0

fromBrand

Signature

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

Added in v1.0.0

instanceOf

Signature

export declare const instanceOf: <A extends abstract new (...args: any) => any>(
  constructor: A,
  annotations?: Annotations.Schema<InstanceType<A>, readonly []> | undefined
) => instanceOf<InstanceType<A>>

Added in v1.0.0

literal

Signature

export declare function literal<Literals extends ReadonlyArray.NonEmptyReadonlyArray<AST.LiteralValue>>(
  ...literals: Literals
): literal<Literals>
export declare function literal(): $never
export declare function literal<Literals extends ReadonlyArray<AST.LiteralValue>>(
  ...literals: Literals
): Schema<Literals[number]>

Added in v1.0.0

make

Signature

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

Added in v1.0.0

pickLiteral

Creates a new Schema from a literal schema.

Signature

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

Example

import * as S from "@effect/schema/Schema"
import { Either } from "effect"

const schema = S.literal("a", "b", "c").pipe(S.pickLiteral("a", "b"))

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

Added in v1.0.0

templateLiteral

Signature

export declare const templateLiteral: <T extends [Schema.AnyNoContext, ...Schema.AnyNoContext[]]>(
  ...[head, ...tail]: T
) => Schema<Join<{ [K in keyof T]: Schema.Type<T[K]> }>, Join<{ [K in keyof T]: Schema.Type<T[K]> }>, never>

Added in v1.0.0

transformLiteral

Creates a new Schema which transforms literal values.

Signature

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

Example

import * as S from "@effect/schema/Schema"

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

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

Added in v1.0.0

transformLiterals

Creates a new Schema which maps between corresponding literal values.

Signature

export declare function 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]> }>
export declare function transformLiterals<Encoded extends AST.LiteralValue, Type extends AST.LiteralValue>(
  pairs: [Encoded, Type]
): transformLiteral<Type, Encoded>
export declare function transformLiterals<
  const A extends ReadonlyArray<readonly [from: AST.LiteralValue, to: AST.LiteralValue]>
>(...pairs: A): Schema<A[number][1], A[number][0]>

Example

import * as S from "@effect/schema/Schema"

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

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

Added in v1.0.0

uniqueSymbolFromSelf

Signature

export declare const uniqueSymbolFromSelf: <S extends symbol>(symbol: S) => Schema<S, S, never>

Added in v1.0.0

decoding

decode

Signature

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

Added in v1.0.0

decodeEither

Signature

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

Added in v1.0.0

decodeOption

Signature

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

Added in v1.0.0

decodePromise

Signature

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

Added in v1.0.0

decodeSync

Signature

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

Added in v1.0.0

decodeUnknown

Signature

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

Added in v1.0.0

decodeUnknownEither

Signature

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

Added in v1.0.0

decodeUnknownOption

Signature

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

Added in v1.0.0

decodeUnknownPromise

Signature

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

Added in v1.0.0

decodeUnknownSync

Signature

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

Added in v1.0.0

encoding

encode

Signature

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

Added in v1.0.0

encodeEither

Signature

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

Added in v1.0.0

encodeOption

Signature

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

Added in v1.0.0

encodePromise

Signature

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

Added in v1.0.0

encodeSync

Signature

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

Added in v1.0.0

encodeUnknown

Signature

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

Added in v1.0.0

encodeUnknownEither

Signature

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

Added in v1.0.0

encodeUnknownOption

Signature

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

Added in v1.0.0

encodeUnknownPromise

Signature

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

Added in v1.0.0

encodeUnknownSync

Signature

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

Added in v1.0.0

formatting

format

Signature

export declare const format: <A, I, R>(schema: Schema<A, I, R>) => string

Added in v1.0.0

guards

isSchema

Tests if a value is a Schema.

Signature

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

Added in v1.0.0

hashing

hash

Signature

export declare const hash: <A, I, R>(schema: Schema<A, I, R>) => number

Added in v1.0.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 ast: AST.AST
  annotations(annotations: Annotations.Schema<A>): Schema<A, I, R>
}

Added in v1.0.0

number constructors

Finite

Signature

export declare const Finite: $number

Added in v1.0.0

Int

Signature

export declare const Int: $number

Added in v1.0.0

JsonNumber

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

Signature

export declare const JsonNumber: $number

Example

import * as S from "@effect/schema/Schema"

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

Added in v1.0.0

Negative

Signature

export declare const Negative: $number

Added in v1.0.0

NonNaN

Signature

export declare const NonNaN: $number

Added in v1.0.0

NonNegative

Signature

export declare const NonNegative: $number

Added in v1.0.0

NonPositive

Signature

export declare const NonPositive: $number

Added in v1.0.0

NumberFromString

This schema transforms a string into a number by parsing the string using the Number function.

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

export declare const NumberFromString: NumberFromString

Added in v1.0.0

Positive

Signature

export declare const Positive: $number

Added in v1.0.0

number filters

between

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

Signature

export declare const between: <A extends number>(
  min: number,
  max: number,
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

finite

Ensures that the provided value is a finite number.

This schema filters out non-finite numeric values, allowing only finite numbers to pass through.

Signature

export declare const finite: <A extends number>(
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

greaterThan

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

Signature

export declare const greaterThan: <A extends number>(
  min: number,
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

greaterThanOrEqualTo

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

Signature

export declare const greaterThanOrEqualTo: <A extends number>(
  min: number,
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

int

Signature

export declare const int: <A extends number>(
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

lessThan

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

Signature

export declare const lessThan: <A extends number>(
  max: number,
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

lessThanOrEqualTo

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

Signature

export declare const lessThanOrEqualTo: <A extends number>(
  max: number,
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

multipleOf

Signature

export declare const multipleOf: <A extends number>(
  divisor: number,
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

negative

Signature

export declare const negative: <A extends number>(
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

nonNaN

Signature

export declare const nonNaN: <A extends number>(
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

nonNegative

Signature

export declare const nonNegative: <A extends number>(
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

nonPositive

Signature

export declare const nonPositive: <A extends number>(
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

positive

Signature

export declare const positive: <A extends number>(
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

number transformations

clamp

Clamps a number between a minimum and a maximum value.

Signature

export declare const clamp: (
  minimum: number,
  maximum: number
) => <R, I, A extends number>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

primitives

any

Signature

export declare const any: $any

Added in v1.0.0

bigintFromSelf

Signature

export declare const bigintFromSelf: bigintFromSelf

Added in v1.0.0

boolean

Signature

export declare const boolean: $boolean

Added in v1.0.0

never

Signature

export declare const never: $never

Added in v1.0.0

null

Signature

export declare const null: $null

Added in v1.0.0

number

Signature

export declare const number: $number

Added in v1.0.0

object

Signature

export declare const object: $object

Added in v1.0.0

string

Signature

export declare const string: $string

Added in v1.0.0

symbolFromSelf

Signature

export declare const symbolFromSelf: symbolFromSelf

Added in v1.0.0

undefined

Signature

export declare const undefined: $undefined

Added in v1.0.0

unknown

Signature

export declare const unknown: $unknown

Added in v1.0.0

void

Signature

export declare const void: $void

Added in v1.0.0

renaming

rename

Signature

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

Added in v1.0.0

string constructors

Char

A schema representing a single character.

Signature

export declare const Char: any

Added in v1.0.0

Lowercased

Signature

export declare const Lowercased: $string

Added in v1.0.0

NonEmpty

Signature

export declare const NonEmpty: $string

Added in v1.0.0

Trimmed

Signature

export declare const Trimmed: $string

Added in v1.0.0

ULID

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

export declare const ULID: $string

Added in v1.0.0

UUID

Represents a Universally Unique Identifier (UUID).

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

Signature

export declare const UUID: $string

Added in v1.0.0

Uppercased

Signature

export declare const Uppercased: $string

Added in v1.0.0

string filters

endsWith

Signature

export declare const endsWith: <A extends string>(
  endsWith: string,
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

includes

Signature

export declare const includes: <A extends string>(
  searchString: string,
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

length

Signature

export declare const length: <A extends string>(
  length: number | { readonly min: number; readonly max: number },
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

lowercased

Verifies that a string is lowercased.

Signature

export declare const lowercased: <A extends string>(
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

maxLength

Signature

export declare const maxLength: <A extends string>(
  maxLength: number,
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

minLength

Signature

export declare const minLength: <A extends string>(
  minLength: number,
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

nonEmpty

Signature

export declare const nonEmpty: <A extends string>(
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

pattern

Signature

export declare const pattern: <A extends string>(
  regex: RegExp,
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

startsWith

Signature

export declare const startsWith: <A extends string>(
  startsWith: string,
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.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

export declare const trimmed: <A extends string>(
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

uppercased

Verifies that a string is uppercased.

Signature

export declare const uppercased: <A extends string>(
  annotations?: Annotations.Filter<A> | undefined
) => <I, R>(self: Schema<A, I, R>) => Schema<A, I, R>

Added in v1.0.0

string transformations

Lowercase

This schema converts a string to lowercase.

Signature

export declare const Lowercase: Lowercase

Added in v1.0.0

Trim

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

Signature

export declare const Trim: Trim

Added in v1.0.0

Uppercase

This schema converts a string to uppercase.

Signature

export declare const Uppercase: Uppercase

Added in v1.0.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.

Signature

export declare const parseJson: {
  <A, I, R>(schema: Schema<A, I, R>, options?: ParseJsonOptions): Schema<A, string, R>
  (options?: ParseJsonOptions): Schema<unknown, string>
}

Example

import * as S from "@effect/schema/Schema"

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

Added in v1.0.0

split

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

Signature

export declare const split: (separator: string) => Schema<ReadonlyArray<string>, string>

Added in v1.0.0

struct transformations

omit

Signature

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

Added in v1.0.0

pick

Signature

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

Added in v1.0.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].

Signature

export declare const pluck: {
  <A, I, K extends keyof A & keyof I>(
    key: K
  ): <R>(schema: Schema<A, I, R>) => Schema<A[K], { readonly [P in K]: I[P] }, R>
  <A, I, R, K extends keyof A & keyof I>(schema: Schema<A, I, R>, key: K): Schema<A[K], { readonly [P in K]: I[P] }, R>
}

Example

import * as S from "@effect/schema/Schema"

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

const mytable = S.struct({
  column1: S.NumberFromString,
  column2: S.number
})

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

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

Added in v1.0.0

symbol

PropertySignatureTypeId

Signature

export declare const PropertySignatureTypeId: typeof PropertySignatureTypeId

Added in v1.0.0

PropertySignatureTypeId (type alias)

Signature

export type PropertySignatureTypeId = typeof PropertySignatureTypeId

Added in v1.0.0

TypeId

Signature

export declare const TypeId: typeof TypeId

Added in v1.0.0

TypeId (type alias)

Signature

export type TypeId = typeof TypeId

Added in v1.0.0

symbol transformations

symbol

This schema transforms a string into a symbol.

Signature

export declare const symbol: $symbol

Added in v1.0.0

type id

BetweenBigDecimalTypeId

Signature

export declare const BetweenBigDecimalTypeId: typeof BetweenBigDecimalTypeId

Added in v1.0.0

BetweenBigintTypeId

Signature

export declare const BetweenBigintTypeId: typeof BetweenBigintTypeId

Added in v1.0.0

BetweenBigintTypeId (type alias)

Signature

export type BetweenBigintTypeId = typeof BetweenBigintTypeId

Added in v1.0.0

BetweenDurationTypeId

Signature

export declare const BetweenDurationTypeId: typeof BetweenDurationTypeId

Added in v1.0.0

BetweenTypeId

Signature

export declare const BetweenTypeId: typeof BetweenTypeId

Added in v1.0.0

BetweenTypeId (type alias)

Signature

export type BetweenTypeId = typeof BetweenTypeId

Added in v1.0.0

BrandTypeId

Signature

export declare const BrandTypeId: typeof BrandTypeId

Added in v1.0.0

EndsWithTypeId

Signature

export declare const EndsWithTypeId: typeof EndsWithTypeId

Added in v1.0.0

FiniteTypeId

Signature

export declare const FiniteTypeId: typeof FiniteTypeId

Added in v1.0.0

GreaterThanBigDecimalTypeId

Signature

export declare const GreaterThanBigDecimalTypeId: typeof GreaterThanBigDecimalTypeId

Added in v1.0.0

GreaterThanBigintTypeId

Signature

export declare const GreaterThanBigintTypeId: typeof GreaterThanBigintTypeId

Added in v1.0.0

GreaterThanBigintTypeId (type alias)

Signature

export type GreaterThanBigintTypeId = typeof GreaterThanBigintTypeId

Added in v1.0.0

GreaterThanDurationTypeId

Signature

export declare const GreaterThanDurationTypeId: typeof GreaterThanDurationTypeId

Added in v1.0.0

GreaterThanOrEqualToBigDecimalTypeId

Signature

export declare const GreaterThanOrEqualToBigDecimalTypeId: typeof GreaterThanOrEqualToBigDecimalTypeId

Added in v1.0.0

GreaterThanOrEqualToBigintTypeId

Signature

export declare const GreaterThanOrEqualToBigintTypeId: typeof GreaterThanOrEqualToBigintTypeId

Added in v1.0.0

GreaterThanOrEqualToBigintTypeId (type alias)

Signature

export type GreaterThanOrEqualToBigintTypeId = typeof GreaterThanOrEqualToBigintTypeId

Added in v1.0.0

GreaterThanOrEqualToDurationTypeId

Signature

export declare const GreaterThanOrEqualToDurationTypeId: typeof GreaterThanOrEqualToDurationTypeId

Added in v1.0.0

GreaterThanOrEqualToTypeId

Signature

export declare const GreaterThanOrEqualToTypeId: typeof GreaterThanOrEqualToTypeId

Added in v1.0.0

GreaterThanOrEqualToTypeId (type alias)

Signature

export type GreaterThanOrEqualToTypeId = typeof GreaterThanOrEqualToTypeId

Added in v1.0.0

GreaterThanTypeId

Signature

export declare const GreaterThanTypeId: typeof GreaterThanTypeId

Added in v1.0.0

GreaterThanTypeId (type alias)

Signature

export type GreaterThanTypeId = typeof GreaterThanTypeId

Added in v1.0.0

IncludesTypeId

Signature

export declare const IncludesTypeId: typeof IncludesTypeId

Added in v1.0.0

InstanceOfTypeId

Signature

export declare const InstanceOfTypeId: typeof InstanceOfTypeId

Added in v1.0.0

IntTypeId

Signature

export declare const IntTypeId: typeof IntTypeId

Added in v1.0.0

IntTypeId (type alias)

Signature

export type IntTypeId = typeof IntTypeId

Added in v1.0.0

ItemsCountTypeId

Signature

export declare const ItemsCountTypeId: typeof ItemsCountTypeId

Added in v1.0.0

ItemsCountTypeId (type alias)

Signature

export type ItemsCountTypeId = typeof ItemsCountTypeId

Added in v1.0.0

JsonNumberTypeId

Signature

export declare const JsonNumberTypeId: typeof JsonNumberTypeId

Added in v1.0.0

LengthTypeId

Signature

export declare const LengthTypeId: typeof LengthTypeId

Added in v1.0.0

LengthTypeId (type alias)

Signature

export type LengthTypeId = typeof LengthTypeId

Added in v1.0.0

LessThanBigDecimalTypeId

Signature

export declare const LessThanBigDecimalTypeId: typeof LessThanBigDecimalTypeId

Added in v1.0.0

LessThanBigintTypeId

Signature

export declare const LessThanBigintTypeId: typeof LessThanBigintTypeId

Added in v1.0.0

LessThanBigintTypeId (type alias)

Signature

export type LessThanBigintTypeId = typeof LessThanBigintTypeId

Added in v1.0.0

LessThanDurationTypeId

Signature

export declare const LessThanDurationTypeId: typeof LessThanDurationTypeId

Added in v1.0.0

LessThanOrEqualToBigDecimalTypeId

Signature

export declare const LessThanOrEqualToBigDecimalTypeId: typeof LessThanOrEqualToBigDecimalTypeId

Added in v1.0.0

LessThanOrEqualToBigintTypeId

Signature

export declare const LessThanOrEqualToBigintTypeId: typeof LessThanOrEqualToBigintTypeId

Added in v1.0.0

LessThanOrEqualToBigintTypeId (type alias)

Signature

export type LessThanOrEqualToBigintTypeId = typeof LessThanOrEqualToBigintTypeId

Added in v1.0.0

LessThanOrEqualToDurationTypeId

Signature

export declare const LessThanOrEqualToDurationTypeId: typeof LessThanOrEqualToDurationTypeId

Added in v1.0.0

LessThanOrEqualToTypeId

Signature

export declare const LessThanOrEqualToTypeId: typeof LessThanOrEqualToTypeId

Added in v1.0.0

LessThanOrEqualToTypeId (type alias)

Signature

export type LessThanOrEqualToTypeId = typeof LessThanOrEqualToTypeId

Added in v1.0.0

LessThanTypeId

Signature

export declare const LessThanTypeId: typeof LessThanTypeId

Added in v1.0.0

LessThanTypeId (type alias)

Signature

export type LessThanTypeId = typeof LessThanTypeId

Added in v1.0.0

LowercasedTypeId

Signature

export declare const LowercasedTypeId: typeof LowercasedTypeId

Added in v1.0.0

MaxItemsTypeId

Signature

export declare const MaxItemsTypeId: typeof MaxItemsTypeId

Added in v1.0.0

MaxItemsTypeId (type alias)

Signature

export type MaxItemsTypeId = typeof MaxItemsTypeId

Added in v1.0.0

MaxLengthTypeId

Signature

export declare const MaxLengthTypeId: typeof MaxLengthTypeId

Added in v1.0.0

MaxLengthTypeId (type alias)

Signature

export type MaxLengthTypeId = typeof MaxLengthTypeId

Added in v1.0.0

MinItemsTypeId

Signature

export declare const MinItemsTypeId: typeof MinItemsTypeId

Added in v1.0.0

MinItemsTypeId (type alias)

Signature

export type MinItemsTypeId = typeof MinItemsTypeId

Added in v1.0.0

MinLengthTypeId

Signature

export declare const MinLengthTypeId: typeof MinLengthTypeId

Added in v1.0.0

MinLengthTypeId (type alias)

Signature

export type MinLengthTypeId = typeof MinLengthTypeId

Added in v1.0.0

MultipleOfTypeId

Signature

export declare const MultipleOfTypeId: typeof MultipleOfTypeId

Added in v1.0.0

NegativeBigDecimalTypeId

Signature

export declare const NegativeBigDecimalTypeId: typeof NegativeBigDecimalTypeId

Added in v1.0.0

NonNaNTypeId

Signature

export declare const NonNaNTypeId: typeof NonNaNTypeId

Added in v1.0.0

NonNegativeBigDecimalTypeId

Signature

export declare const NonNegativeBigDecimalTypeId: typeof NonNegativeBigDecimalTypeId

Added in v1.0.0

NonPositiveBigDecimalTypeId

Signature

export declare const NonPositiveBigDecimalTypeId: typeof NonPositiveBigDecimalTypeId

Added in v1.0.0

PatternTypeId

Signature

export declare const PatternTypeId: typeof PatternTypeId

Added in v1.0.0

PositiveBigDecimalTypeId

Signature

export declare const PositiveBigDecimalTypeId: typeof PositiveBigDecimalTypeId

Added in v1.0.0

StartsWithTypeId

Signature

export declare const StartsWithTypeId: typeof StartsWithTypeId

Added in v1.0.0

TrimmedTypeId

Signature

export declare const TrimmedTypeId: typeof TrimmedTypeId

Added in v1.0.0

ULIDTypeId

Signature

export declare const ULIDTypeId: typeof ULIDTypeId

Added in v1.0.0

UUIDTypeId

Signature

export declare const UUIDTypeId: typeof UUIDTypeId

Added in v1.0.0

UppercasedTypeId

Signature

export declare const UppercasedTypeId: typeof UppercasedTypeId

Added in v1.0.0

ValidDateTypeId

Signature

export declare const ValidDateTypeId: typeof ValidDateTypeId

Added in v1.0.0

utils

IndexSignature (namespace)

Added in v1.0.0

Context (type alias)

Signature

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

Added in v1.0.0

Encoded (type alias)

Signature

export type Encoded<Records extends IndexSignature.Records> = Types.UnionToIntersection<
  {
    [K in keyof Records]: {
      readonly [P in Schema.Encoded<Records[K]["key"]>]: Schema.Encoded<Records[K]["value"]>
    }
  }[number]
>

Added in v1.0.0

NonEmptyRecords (type alias)

Signature

export type NonEmptyRecords = ReadonlyArray.NonEmptyReadonlyArray<Record>

Added in v1.0.0

Record (type alias)

Signature

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

Added in v1.0.0

Records (type alias)

Signature

export type Records = ReadonlyArray<Record>

Added in v1.0.0

Type (type alias)

Signature

export type Type<Records extends IndexSignature.Records> = Types.UnionToIntersection<
  {
    [K in keyof Records]: {
      readonly [P in Schema.Type<Records[K]["key"]>]: Schema.Type<Records[K]["value"]>
    }
  }[number]
>

Added in v1.0.0

OptionalElement (interface)

Signature

export interface OptionalElement<E extends Schema.Any>
  extends Schema.Variance<Schema.Type<E>, Schema.Encoded<E>, Schema.Context<E>> {
  readonly optionalElement: E
}

Added in v1.0.0

ParseJsonOptions (type alias)

Signature

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

Added in v1.0.0

PropertySignature (namespace)

Added in v1.0.0

Annotations (interface)

Signature

export interface Annotations<A> extends Annotations.Doc<A> {}

Added in v1.0.0

AST (type alias)

Signature

export type AST = PropertySignatureDeclaration | PropertySignatureTransformation

Added in v1.0.0

All (type alias)

Signature

export type All<Key extends PropertyKey = PropertyKey> =
  | Any<Key>
  | PropertySignature<Token, never, Key, Token, any, unknown>
  | PropertySignature<Token, any, Key, Token, never, unknown>
  | PropertySignature<Token, never, Key, Token, never, unknown>

Added in v1.0.0

Any (type alias)

Signature

export type Any<Key extends PropertyKey = PropertyKey> = PropertySignature<Token, any, Key, Token, any, unknown>

Added in v1.0.0

GetToken (type alias)

Signature

export type GetToken<B extends boolean> = B extends true ? "?:" : ":"

Added in v1.0.0

Token (type alias)

Signature

export type Token = "?:" | ":"

Added in v1.0.0

Schema (namespace)

Added in v1.0.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>
  }
}

Added in v1.0.0

All (type alias)

Any schema, including never.

Signature

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

Added in v1.0.0

Any (type alias)

Any schema, except for never.

Signature

export type Any = Schema<any, any, unknown>

Added in v1.0.0

AnyNoContext (type alias)

Any schema with Context = never, except for never.

Signature

export type AnyNoContext = Schema<any, any, never>

Added in v1.0.0

Context (type alias)

Signature

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

Added in v1.0.0

Encoded (type alias)

Signature

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

Added in v1.0.0

ToAsserts (type alias)

Signature

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

Added in v1.0.0

Type (type alias)

Signature

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

Added in v1.0.0

Simplify (type alias)

Required to fix a bug in TypeScript@5.0, dtslint fails with: TypeScript@5.0 expected type to be: { readonly [x: string]: number; } got: { [x: string]: number; }

Signature

export type Simplify<T> = { readonly [K in keyof T]: T[K] } & {}

Added in v1.0.0

SimplifyMutable (type alias)

Signature

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

Added in v1.0.0

Struct (namespace)

Added in v1.0.0

Context (type alias)

Signature

export type Context<F extends Fields> = Schema.Context<F[keyof F]>

Added in v1.0.0

Encoded (type alias)

Signature

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

Added in v1.0.0

Fields (type alias)

Signature

export type Fields = {
  readonly [x: PropertyKey]: Schema.All | PropertySignature.All
}

Added in v1.0.0

Type (type alias)

Signature

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

Added in v1.0.0

TupleType (namespace)

Added in v1.0.0

Element (type alias)

Signature

export type Element = Schema.Any | OptionalElement<Schema.Any>

Added in v1.0.0

Elements (type alias)

Signature

export type Elements = ReadonlyArray<Element>

Added in v1.0.0

Encoded (type alias)

Signature

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

Added in v1.0.0

Type (type alias)

Signature

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

Added in v1.0.0

TypeLiteral (namespace)

Added in v1.0.0

Encoded (type alias)

Signature

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

Added in v1.0.0

Type (type alias)

Signature

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

Added in v1.0.0

asSchema

Signature

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

Added in v1.0.0

encodedSchema

Signature

export declare const encodedSchema: <A, I, R>(schema: Schema<A, I, R>) => Schema<I, I, never>

Added in v1.0.0

optionalElement

Signature

export declare const optionalElement: <E extends Schema.Any>(self: E) => OptionalElement<E>

Added in v1.0.0

typeSchema

Signature

export declare const typeSchema: <A, I, R>(schema: Schema<A, I, R>) => Schema<A, A, never>

Added in v1.0.0

validation

asserts

Signature

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

Added in v1.0.0

is

Signature

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

Added in v1.0.0

validate

Signature

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

Added in v1.0.0

validateEither

Signature

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

Added in v1.0.0

validateOption

Signature

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

Added in v1.0.0

validatePromise

Signature

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

Added in v1.0.0

validateSync

Signature

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

Added in v1.0.0