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

Schema overview

Added in v0.67.0


Table of contents


API interface

Element (interface)

Signature

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

Added in v0.68.0

TemplateLiteral (interface)

Signature

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

Added in v0.67.17

propertySignature (interface)

Signature

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

Added in v1.0.0

BigDecimal constructors

BigDecimalFromSelf (class)

Signature

export declare class BigDecimalFromSelf

Added in v0.67.0

NegativeBigDecimalFromSelf

Signature

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

Added in v0.67.0

NonNegativeBigDecimalFromSelf

Signature

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

Added in v0.67.0

NonPositiveBigDecimalFromSelf

Signature

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

Added in v0.67.0

PositiveBigDecimalFromSelf

Signature

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

Added in v0.67.0

BigDecimal filters

betweenBigDecimal

Signature

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

Added in v0.67.0

greaterThanBigDecimal

Signature

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

Added in v0.67.0

greaterThanOrEqualToBigDecimal

Signature

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

Added in v0.67.0

lessThanBigDecimal

Signature

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

Added in v0.67.0

lessThanOrEqualToBigDecimal

Signature

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

Added in v0.67.0

negativeBigDecimal

Signature

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

Added in v0.67.0

nonNegativeBigDecimal

Signature

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

Added in v0.67.0

nonPositiveBigDecimal

Signature

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

Added in v0.67.0

positiveBigDecimal

Signature

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

Added in v0.67.0

BigDecimal transformations

BigDecimal (class)

Signature

export declare class BigDecimal

Added in v0.67.0

BigDecimalFromNumber (class)

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

Signature

export declare class BigDecimalFromNumber

Added in v0.67.0

clampBigDecimal

Clamps a BigDecimal between a minimum and a maximum value.

Signature

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

Added in v0.67.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 v0.67.0

CauseDefectUnknown

Signature

export declare const CauseDefectUnknown: transform<typeof Unknown, typeof Unknown>

Added in v0.67.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 v0.67.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 v0.67.0

Chunk

ChunkFromSelf

Signature

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

Added in v0.67.0

NonEmptyChunkFromSelf

Signature

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

Added in v0.67.23

Chunk transformations

Chunk

Signature

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

Added in v0.67.0

NonEmptyChunk

Signature

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

Added in v0.67.23

Config validations

Config

Signature

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

Added in v0.67.12

Data transformations

Data

Signature

export declare const Data: <
  R,
  I extends readonly any[] | Readonly<Record<string, any>>,
  A extends readonly any[] | Readonly<Record<string, any>>
>(
  item: Schema<A, I, R>
) => SchemaClass<A, I, R>

Added in v0.67.0

DataFromSelf

Signature

export declare const DataFromSelf: <
  R,
  I extends readonly any[] | Readonly<Record<string, any>>,
  A extends readonly any[] | Readonly<Record<string, any>>
>(
  item: Schema<A, I, R>
) => SchemaClass<A, I, R>

Added in v0.67.0

Date constructors

DateFromSelf (class)

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

Signature

export declare class DateFromSelf

Added in v0.67.0

ValidDateFromSelf (class)

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

Signature

export declare class ValidDateFromSelf

Added in v0.67.0

Date filters

validDate

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

Signature

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

Added in v0.67.0

Date transformations

Date

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

Signature

export declare const Date: typeof Date$

Added in v0.67.0

DateFromNumber (class)

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

Signature

export declare class DateFromNumber

Added in v0.67.0

DateFromString (class)

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

Signature

export declare class DateFromString

Added in v0.67.0

Duration constructors

DurationFromSelf (class)

Signature

export declare class DurationFromSelf

Added in v0.67.0

Duration filters

betweenDuration

Signature

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

Added in v0.67.0

greaterThanDuration

Signature

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

Added in v0.67.0

greaterThanOrEqualToDuration

Signature

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

Added in v0.67.0

lessThanDuration

Signature

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

Added in v0.67.0

lessThanOrEqualToDuration

Signature

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

Added in v0.67.0

Duration transformations

Duration (class)

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

Signature

export declare class Duration

Added in v0.67.0

DurationFromMillis (class)

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

Signature

export declare class DurationFromMillis

Added in v0.67.0

DurationFromNanos (class)

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

Signature

export declare class DurationFromNanos

Added in v0.67.0

clampDuration

Clamps a Duration between a minimum and a maximum value.

Signature

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

Added in v0.67.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 v0.67.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 v0.67.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 v0.67.0

Either utils

EitherEncoded (type alias)

Signature

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

Added in v0.67.0

LeftEncoded (type alias)

Signature

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

Added in v0.67.0

RightEncoded (type alias)

Signature

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

Added in v0.67.0

Encoding transformations

Base64

Signature

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

Added in v0.67.0

Base64Url

Signature

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

Added in v0.67.0

Hex

Signature

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

Added in v0.67.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 v0.67.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 v0.67.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 v0.67.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 v0.67.0

FiberId constructors

FiberIdFromSelf (class)

Signature

export declare class FiberIdFromSelf

Added in v0.67.0

FiberId transformations

FiberId (class)

Signature

export declare class FiberId

Added in v0.67.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 v0.67.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 v0.67.0

HashSet transformations

HashSet

Signature

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

Added in v0.67.0

HashSetFromSelf

Signature

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

Added in v0.67.0

List transformations

List

Signature

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

Added in v0.67.0

ListFromSelf

Signature

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

Added in v0.67.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 v0.67.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 v0.67.0

MapFromRecord

Signature

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

Added in v0.68.15

Option transformations

Option

Signature

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

Added in v0.67.0

OptionFromNullOr

Signature

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

Added in v0.67.0

OptionFromNullishOr

Signature

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

Added in v0.67.0

OptionFromSelf

Signature

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

Added in v0.67.0

OptionFromUndefinedOr

Signature

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

Added in v0.67.0

Option utils

OptionEncoded (type alias)

Signature

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

Added in v0.67.0

PropertySignature

FromPropertySignature (class)

Signature

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

Added in v0.67.0

PropertySignature (interface)

Signature

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

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

Added in v0.67.0

PropertySignatureDeclaration (class)

Signature

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

Added in v0.67.0

toString (method)

Signature

toString()

Added in v0.67.0

_tag (property)

Signature

readonly _tag: "PropertySignatureDeclaration"

Added in v0.67.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 v0.67.0

toString (method)

Signature

toString()

Added in v0.67.0

_tag (property)

Signature

readonly _tag: "PropertySignatureTransformation"

Added in v0.67.0

ToPropertySignature (class)

Signature

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

Added in v0.67.0

fromKey

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

Signature

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

Added in v0.67.0

makePropertySignature

Signature

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

Added in v0.67.15

optional

Signature

export declare const optional: {
  <S extends Schema.All, Options extends OptionalOptions<Schema.Type<S>>>(
    options?: Options | undefined
  ): (self: S) => [undefined] extends [Options] ? optional<S> : optionalWithOptions<S, Options>
  <S extends Schema.All, Options extends OptionalOptions<Schema.Type<S>>>(
    self: Schema.All extends S ? "you can't apply optional implicitly, use optional() instead" : S,
    options?: Options | undefined
  ): [undefined] extends [Options] ? optional<S> : optionalWithOptions<S, Options>
}

Added in v0.67.0

optionalToOptional

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

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

Signature

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

Added in v0.67.0

optionalToRequired

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

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

Signature

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

Added in v0.67.0

propertySignature

Lifts a Schema into a PropertySignature.

Signature

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

Added in v0.67.0

requiredToOptional

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

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

Signature

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

Added in v0.67.15

withConstructorDefault

Enhances a property signature with a default constructor value.

Signature

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

Added in v0.67.0

withDecodingDefault

Enhances a property signature with a default decoding value.

Signature

export declare const withDecodingDefault: {
  <Type>(
    defaultValue: () => Types.NoInfer<Type>
  ): <Key extends PropertyKey, Encoded, HasDefault extends boolean, R>(
    self: PropertySignature<"?:", Type, Key, "?:", Encoded, HasDefault, R>
  ) => PropertySignature<":", Exclude<Type, undefined>, Key, "?:", Encoded, HasDefault, R>
  <Type, Key extends PropertyKey, Encoded, HasDefault extends boolean, R>(
    self: PropertySignature<"?:", Type, Key, "?:", Encoded, HasDefault, R>,
    defaultValue: () => Types.NoInfer<Type>
  ): PropertySignature<":", Exclude<Type, undefined>, Key, "?:", Encoded, HasDefault, R>
}

Added in v0.67.0

withDefaults

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

Signature

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

Added in v0.67.0

ReadonlyArray filters

itemsCount

Signature

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

Added in v0.67.0

maxItems

Signature

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

Added in v0.67.0

minItems

Signature

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

Added in v0.67.0

ReadonlyArray transformations

getNumberIndexedAccess

Signature

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

Added in v0.67.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<readonly A[], I, R>) => SchemaClass<option_.Option<A>, I, R>

Added in v0.67.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<readonly A[], I, R>) => SchemaClass<A, I, R>
  <A, I, R>(self: Schema<readonly A[], I, R>, fallback?: any): SchemaClass<A, I, R>
}

Added in v0.67.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 v0.67.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 v0.67.0

ReadonlyMapFromRecord

Signature

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

Added in v0.68.15

ReadonlySet

ReadonlySetFromSelf

Signature

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

Added in v0.67.0

ReadonlySet transformations

ReadonlySet

Signature

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

Added in v0.67.0

Redacted constructors

RedactedFromSelf

Signature

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

Added in v0.67.21

Redacted transformations

Redacted

A schema that transforms any type A into a Redacted<A>.

Signature

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

Added in v0.67.21

Set

SetFromSelf

Signature

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

Added in v0.67.0

Set transformations

Set

Signature

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

Added in v0.67.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 v0.67.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 v0.67.0

Uint8Array constructors

Uint8ArrayFromSelf

Signature

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

Added in v0.67.0

Uint8Array transformations

Uint8Array

A schema that transforms a number array into a Uint8Array.

Signature

export declare const Uint8Array: Schema<Uint8Array, readonly number[], never>

Added in v0.67.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 v0.67.0

Annotable (namespace)

Added in v0.67.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 v0.67.0

Any (type alias)

Signature

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

Added in v0.67.0

Self (type alias)

Signature

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

Added in v0.67.0

AnnotableClass (interface)

Signature

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

Added in v0.67.0

Annotations (namespace)

Added in v0.67.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 v0.67.0

Filter (interface)

Signature

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

Added in v0.67.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
  readonly parseOptions?: AST.ParseOptions
}

Added in v0.67.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 v0.67.0

api interface

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 v0.67.0

Cause (interface)

Signature

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

Added in v0.67.0

CauseFromSelf (interface)

Signature

export interface CauseFromSelf<E extends Schema.Any, DR>
  extends AnnotableClass<
    CauseFromSelf<E, DR>,
    cause_.Cause<Schema.Type<E>>,
    cause_.Cause<Schema.Encoded<E>>,
    Schema.Context<E> | DR
  > {}

Added in v0.67.0

Chunk (interface)

Signature

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

Added in v0.67.0

ChunkFromSelf (interface)

Signature

export interface ChunkFromSelf<Value extends Schema.Any>
  extends AnnotableClass<
    ChunkFromSelf<Value>,
    chunk_.Chunk<Schema.Type<Value>>,
    chunk_.Chunk<Schema.Encoded<Value>>,
    Schema.Context<Value>
  > {}

Added in v0.67.0

Class (interface)

Signature

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

  make<Args extends Array<any>, X>(this: { new (...args: Args): X }, ...args: Args): X

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

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

  readonly identifier: string

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

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

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

Added in v0.67.0

Either (interface)

Signature

export interface Either<R extends Schema.Any, L extends Schema.Any>
  extends AnnotableClass<
    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 v0.67.0

EitherFromSelf (interface)

Signature

export interface EitherFromSelf<R extends Schema.Any, L extends Schema.Any>
  extends AnnotableClass<
    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 v0.67.0

EitherFromUnion (interface)

Signature

export interface EitherFromUnion<R extends Schema.Any, L extends Schema.Any>
  extends AnnotableClass<
    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 v0.67.0

Enums (interface)

Signature

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

Added in v0.67.0

Exit (interface)

Signature

export interface Exit<A extends Schema.All, E extends Schema.All, DR>
  extends AnnotableClass<
    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 v0.67.0

ExitFromSelf (interface)

Signature

export interface ExitFromSelf<A extends Schema.Any, E extends Schema.Any, DR>
  extends AnnotableClass<
    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 v0.67.0

HashMap (interface)

Signature

export interface HashMap<K extends Schema.Any, V extends Schema.Any>
  extends AnnotableClass<
    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 v0.67.0

HashMapFromSelf (interface)

Signature

export interface HashMapFromSelf<K extends Schema.Any, V extends Schema.Any>
  extends AnnotableClass<
    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 v0.67.0

HashSet (interface)

Signature

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

Added in v0.67.0

HashSetFromSelf (interface)

Signature

export interface HashSetFromSelf<Value extends Schema.Any>
  extends AnnotableClass<
    HashSetFromSelf<Value>,
    hashSet_.HashSet<Schema.Type<Value>>,
    hashSet_.HashSet<Schema.Encoded<Value>>,
    Schema.Context<Value>
  > {}

Added in v0.67.0

List (interface)

Signature

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

Added in v0.67.0

ListFromSelf (interface)

Signature

export interface ListFromSelf<Value extends Schema.Any>
  extends AnnotableClass<
    ListFromSelf<Value>,
    list_.List<Schema.Type<Value>>,
    list_.List<Schema.Encoded<Value>>,
    Schema.Context<Value>
  > {}

Added in v0.67.0

Literal (interface)

Signature

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

Added in v0.67.0

Map$ (interface)

Signature

export interface Map$<K extends Schema.Any, V extends Schema.Any>
  extends AnnotableClass<
    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 v0.67.0

MapFromSelf (interface)

Signature

export interface MapFromSelf<K extends Schema.Any, V extends Schema.Any>
  extends AnnotableClass<
    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 v0.67.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 v0.67.0

NonEmptyChunk (interface)

Signature

export interface NonEmptyChunk<Value extends Schema.Any>
  extends AnnotableClass<
    NonEmptyChunk<Value>,
    chunk_.NonEmptyChunk<Schema.Type<Value>>,
    array_.NonEmptyReadonlyArray<Schema.Encoded<Value>>,
    Schema.Context<Value>
  > {}

Added in v0.67.23

NonEmptyChunkFromSelf (interface)

Signature

export interface NonEmptyChunkFromSelf<Value extends Schema.Any>
  extends AnnotableClass<
    NonEmptyChunkFromSelf<Value>,
    chunk_.NonEmptyChunk<Schema.Type<Value>>,
    chunk_.NonEmptyChunk<Schema.Encoded<Value>>,
    Schema.Context<Value>
  > {}

Added in v0.67.23

NullOr (interface)

Signature

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

Added in v0.67.0

NullishOr (interface)

Signature

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

Added in v0.67.0

Option (interface)

Signature

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

Added in v0.67.0

OptionFromNullOr (interface)

Signature

export interface OptionFromNullOr<Value extends Schema.Any>
  extends AnnotableClass<
    OptionFromNullOr<Value>,
    option_.Option<Schema.Type<Value>>,
    Schema.Encoded<Value> | null,
    Schema.Context<Value>
  > {}

Added in v0.67.0

OptionFromNullishOr (interface)

Signature

export interface OptionFromNullishOr<Value extends Schema.Any>
  extends AnnotableClass<
    OptionFromNullishOr<Value>,
    option_.Option<Schema.Type<Value>>,
    Schema.Encoded<Value> | null | undefined,
    Schema.Context<Value>
  > {}

Added in v0.67.0

OptionFromSelf (interface)

Signature

export interface OptionFromSelf<Value extends Schema.Any>
  extends AnnotableClass<
    OptionFromSelf<Value>,
    option_.Option<Schema.Type<Value>>,
    option_.Option<Schema.Encoded<Value>>,
    Schema.Context<Value>
  > {}

Added in v0.67.0

OptionFromUndefinedOr (interface)

Signature

export interface OptionFromUndefinedOr<Value extends Schema.Any>
  extends AnnotableClass<
    OptionFromUndefinedOr<Value>,
    option_.Option<Schema.Type<Value>>,
    Schema.Encoded<Value> | undefined,
    Schema.Context<Value>
  > {}

Added in v0.67.0

ReadonlyMap$ (interface)

Signature

export interface ReadonlyMap$<K extends Schema.Any, V extends Schema.Any>
  extends AnnotableClass<
    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 v0.67.0

ReadonlyMapFromSelf (interface)

Signature

export interface ReadonlyMapFromSelf<K extends Schema.Any, V extends Schema.Any>
  extends AnnotableClass<
    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 v0.67.0

ReadonlySet$ (interface)

Signature

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

Added in v0.67.0

ReadonlySetFromSelf (interface)

Signature

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

Added in v0.67.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 v0.67.0

Redacted (interface)

Signature

export interface Redacted<Value extends Schema.Any>
  extends AnnotableClass<
    Redacted<Value>,
    redacted_.Redacted<Schema.Type<Value>>,
    Schema.Encoded<Value>,
    Schema.Context<Value>
  > {}

Added in v0.67.21

RedactedFromSelf (interface)

Signature

export interface RedactedFromSelf<Value extends Schema.Any>
  extends AnnotableClass<
    RedactedFromSelf<Value>,
    redacted_.Redacted<Schema.Type<Value>>,
    redacted_.Redacted<Schema.Encoded<Value>>,
    Schema.Context<Value>
  > {}

Added in v0.67.21

Set$ (interface)

Signature

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

Added in v0.67.0

SetFromSelf (interface)

Signature

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

Added in v0.67.0

SortedSet (interface)

Signature

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

Added in v0.67.0

SortedSetFromSelf (interface)

Signature

export interface SortedSetFromSelf<Value extends Schema.Any>
  extends AnnotableClass<
    SortedSetFromSelf<Value>,
    sortedSet_.SortedSet<Schema.Type<Value>>,
    sortedSet_.SortedSet<Schema.Encoded<Value>>,
    Schema.Context<Value>
  > {}

Added in v0.67.0

Struct (interface)

Signature

export interface Struct<Fields extends Struct.Fields> extends TypeLiteral<Fields, []> {
  annotations(annotations: Annotations.Schema<Simplify<Struct.Type<Fields>>>): Struct<Fields>
  /** @since 0.68.17 */
  pick<Keys extends ReadonlyArray<keyof Fields>>(...keys: Keys): Struct<Simplify<Pick<Fields, Keys[number]>>>
  /** @since 0.68.17 */
  omit<Keys extends ReadonlyArray<keyof Fields>>(...keys: Keys): Struct<Simplify<Omit<Fields, Keys[number]>>>
}

Added in v0.67.0

TaggedClass (interface)

Signature

export interface TaggedClass<Self, Tag extends string, Fields extends Struct.Fields>
  extends Class<
    Self,
    Fields,
    Struct.Encoded<Fields>,
    Struct.Context<Fields>,
    Struct.Constructor<Omit<Fields, "_tag">>,
    {},
    {}
  > {
  readonly _tag: Tag
}

Added in v0.67.0

TaggedErrorClass (interface)

Signature

export interface TaggedErrorClass<Self, Tag extends string, Fields extends Struct.Fields>
  extends Class<
    Self,
    Fields,
    Struct.Encoded<Fields>,
    Struct.Context<Fields>,
    Struct.Constructor<Omit<Fields, "_tag">>,
    {},
    cause_.YieldableError
  > {
  readonly _tag: Tag
}

Added in v0.67.0

TaggedRequestClass (interface)

Signature

export interface TaggedRequestClass<
  Self,
  Tag extends string,
  Fields extends Struct.Fields,
  Failure extends Schema.All,
  Success extends Schema.All
> extends Class<
    Self,
    Fields,
    Struct.Encoded<Fields>,
    Struct.Context<Fields>,
    Struct.Constructor<Omit<Fields, "_tag">>,
    TaggedRequest<
      Tag,
      Self,
      Struct.Encoded<Fields>,
      Struct.Context<Fields>,
      Schema.Type<Success>,
      Schema.Encoded<Success>,
      Schema.Type<Failure>,
      Schema.Encoded<Failure>,
      Schema.Context<Success> | Schema.Context<Failure>
    >,
    {}
  > {
  readonly _tag: Tag
}

Added in v0.67.0

TaggedStruct (type alias)

Signature

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

Added in v0.67.14

Tuple (interface)

Signature

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

Added in v0.67.0

TupleType (interface)

Signature

export interface TupleType<Elements extends TupleType.Elements, Rest extends TupleType.Rest>
  extends AnnotableClass<
    TupleType<Elements, Rest>,
    TupleType.Type<Elements, Rest>,
    TupleType.Encoded<Elements, Rest>,
    Schema.Context<Elements[number]> | Schema.Context<Rest[number]>
  > {
  readonly elements: Readonly<Elements>
  readonly rest: Readonly<Rest>
}

Added in v0.67.0

TypeLiteral (interface)

Signature

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

Added in v0.67.0

UndefinedOr (interface)

Signature

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

Added in v0.67.0

Union (interface)

Signature

export interface Union<Members extends ReadonlyArray<Schema.Any>>
  extends AnnotableClass<
    Union<Members>,
    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 v0.67.0

brand (interface)

Signature

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

Added in v0.67.0

extend (interface)

Signature

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

Added in v0.67.0

filter (interface)

Signature

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

Added in v0.67.0

filterEffect (interface)

Signature

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

Added in v0.68.17

instanceOf (interface)

Signature

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

Added in v0.67.0

mutable (interface)

Signature

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

Added in v0.67.0

optional (interface)

Signature

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

Added in v0.67.10

optionalWithOptions (interface)

Signature

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

Added in v0.67.10

refine (interface)

Signature

export interface refine<A, From extends Schema.Any>
  extends AnnotableClass<refine<A, From>, A, Schema.Encoded<From>, Schema.Context<From>> {
  readonly [refineTypeId]: From
  readonly from: From
  readonly filter: (
    a: Schema.Type<From>,
    options: ParseOptions,
    self: AST.Refinement
  ) => option_.Option<ParseResult.ParseIssue>
  make(a: Schema.Type<From>, options?: MakeOptions): A
}

Added in v0.67.0

suspend (interface)

Signature

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

Added in v0.67.0

tag (interface)

Signature

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

Added in v0.67.14

transform (interface)

Signature

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

Added in v0.67.0

transformLiteral (interface)

Signature

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

Added in v0.67.0

transformOrFail (interface)

Signature

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

Added in v0.67.0

bigint constructors

NegativeBigInt

Signature

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

Added in v0.67.0

NegativeBigIntFromSelf

Signature

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

Added in v0.67.0

NonNegativeBigInt

Signature

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

Added in v0.67.0

NonNegativeBigIntFromSelf

Signature

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

Added in v0.67.0

NonPositiveBigInt

Signature

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

Added in v0.67.0

NonPositiveBigIntFromSelf

Signature

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

Added in v0.67.0

PositiveBigInt

Signature

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

Added in v0.67.0

PositiveBigIntFromSelf

Signature

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

Added in v0.67.0

bigint filters

betweenBigInt

Signature

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

Added in v0.67.0

greaterThanBigInt

Signature

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

Added in v0.67.0

greaterThanOrEqualToBigInt

Signature

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

Added in v0.67.0

lessThanBigInt

Signature

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

Added in v0.67.0

lessThanOrEqualToBigInt

Signature

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

Added in v0.67.0

negativeBigInt

Signature

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

Added in v0.67.0

nonNegativeBigInt

Signature

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

Added in v0.67.0

nonPositiveBigInt

Signature

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

Added in v0.67.0

positiveBigInt

Signature

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

Added in v0.67.0

bigint transformations

BigInt

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

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

Signature

export declare const BigInt: typeof BigInt$

Added in v0.67.0

BigIntFromNumber (class)

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

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

Signature

export declare class BigIntFromNumber

Added in v0.67.0

clampBigInt

Clamps a bigint between a minimum and a maximum value.

Signature

export declare const clampBigInt: (
  minimum: bigint,
  maximum: bigint
) => <A extends bigint, I, R>(self: Schema<A, I, R>) => transform<Schema<A, I, R>, filter<Schema<A, A, never>>>

Added in v0.67.0

boolean constructors

BooleanFromUnknown (class)

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

Signature

export declare class BooleanFromUnknown

Added in v0.67.0

boolean transformations

Not (class)

Signature

export declare class Not

Added in v0.67.0

branding

BrandSchema (interface)

Signature

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

Added in v0.67.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 v0.67.0

classes

Class

Signature

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

Added in v0.67.0

TaggedClass

Signature

export declare const TaggedClass: <Self = never>(
  identifier?: string
) => <Tag extends string, Fields extends Struct.Fields>(
  tag: Tag,
  fieldsOr: Fields | HasFields<Fields>,
  annotations?: Annotations.Schema<Self, readonly []> | undefined
) => [Self] extends [never]
  ? 'Missing `Self` generic - use `class Self extends TaggedClass<Self>()("Tag", { ... })`'
  : TaggedClass<Self, Tag, { readonly _tag: PropertySignature<":", Tag, never, ":", Tag, true, never> } & Fields>

Added in v0.67.0

TaggedError

Signature

export declare const TaggedError: <Self = never>(
  identifier?: string
) => <Tag extends string, Fields extends Struct.Fields>(
  tag: Tag,
  fieldsOr: Fields | HasFields<Fields>,
  annotations?: Annotations.Schema<Self, readonly []> | undefined
) => [Self] extends [never]
  ? 'Missing `Self` generic - use `class Self extends TaggedError<Self>()("Tag", { ... })`'
  : TaggedErrorClass<Self, Tag, { readonly _tag: PropertySignature<":", Tag, never, ":", Tag, true, never> } & Fields>

Added in v0.67.0

TaggedRequest

Signature

export declare const TaggedRequest: <Self = never>(
  identifier?: string
) => <Tag extends string, Fields extends Struct.Fields, Failure extends Schema.All, Success extends Schema.All>(
  tag: Tag,
  Failure: Failure,
  Success: Success,
  fields: Fields,
  annotations?: Annotations.Schema<Self, readonly []> | undefined
) => [Self] extends [never]
  ? 'Missing `Self` generic - use `class Self extends TaggedRequest<Self>()("Tag", SuccessSchema, FailureSchema, { ... })`'
  : TaggedRequestClass<
      Self,
      Tag,
      { readonly _tag: PropertySignature<":", Tag, never, ":", Tag, true, never> } & Fields,
      Failure,
      Success
    >

Added in v0.67.0

TaggedRequest (interface)

Signature

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

Added in v0.67.0

TaggedRequest (namespace)

Added in v0.67.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 v0.67.0

combinators

NullOr

Signature

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

Added in v0.67.0

NullishOr

Signature

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

Added in v0.67.0

UndefinedOr

Signature

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

Added in v0.67.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(): typeof 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 v0.67.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>(
    key: K,
    value: V,
    annotations?:
      | Annotations.Schema<
          { [K in keyof (A & { readonly [k in K]: V })]: (A & { readonly [k in K]: V })[K] },
          readonly []
        >
      | undefined
  ): <I, R>(
    schema: SchemaClass<A, I, R>
  ) => Schema<{ [K in keyof (A & { readonly [k in K]: V })]: (A & { readonly [k in K]: V })[K] }, 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<
          { [K in keyof (A & { readonly [k in K]: V })]: (A & { readonly [k in K]: V })[K] },
          readonly []
        >
      | undefined
  ): SchemaClass<{ [K in keyof (A & { readonly [k in K]: V })]: (A & { readonly [k in K]: V })[K] }, 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 v0.67.0

compose

Signature

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

Added in v0.67.0

extend

Extends a schema by adding additional fields or index signatures.

  1. It only supports structs, refinements of structs, unions of structs, suspensions of structs (informally Supported = Struct | Refinement of Supported | Union of Supported | suspend(() => Supported))
  2. The arguments must represent disjoint types (e.g., extend(Struct({ a: String }), Struct({ a: String }))) raises an error)

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

Example

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

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

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

Added in v0.67.0

keyof

Signature

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

Added in v0.67.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 v0.67.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>
  ) => SchemaClass<
    { [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
  ): SchemaClass<
    { [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 v0.67.0

required

Signature

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

Added in v0.67.0

constructors

Array

Signature

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

Added in v0.67.0

Enums

Signature

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

Added in v0.67.0

Literal

Signature

export declare function Literal<Literals extends array_.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 v0.67.0

NonEmptyArray

Signature

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

Added in v0.67.0

Record

Signature

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

Added in v0.67.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 v0.67.0

TaggedStruct

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

The tag is optional when using the make method.

Signature

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

Example

import { Schema } from "@effect/schema"

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

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

Added in v0.67.14

TemplateLiteral

Signature

export declare const TemplateLiteral: <T extends readonly [TemplateLiteralParameter, ...TemplateLiteralParameter[]]>(
  ...[head, ...tail]: T
) => TemplateLiteral<Join<T>>

Added in v0.67.0

Tuple

Signature

export declare function Tuple<
  const Elements extends TupleType.Elements,
  Rest extends array_.NonEmptyReadonlyArray<TupleType.Rest[number]>
>(elements: Elements, ...rest: Rest): TupleType<Elements, Rest>
export declare function Tuple<Elements extends TupleType.Elements>(...elements: Elements): Tuple<Elements>

Added in v0.67.0

UniqueSymbolFromSelf

Signature

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

Added in v0.67.0

declare

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

Signature

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

Added in v0.67.0

fromBrand

Signature

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

Added in v0.67.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 v0.67.0

make

Signature

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

Added in v0.67.0

pickLiteral

Creates a new Schema from a literal schema.

Signature

export declare const pickLiteral: <A extends AST.LiteralValue, L extends array_.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 v0.67.0

suspend

Signature

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

Added in v0.67.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 v0.67.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 v0.67.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 v0.67.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 v0.67.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 v0.67.0

decodePromise

Signature

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

Added in v0.67.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 v0.67.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 v0.67.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 v0.67.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 v0.67.0

decodeUnknownPromise

Signature

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

Added in v0.67.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 v0.67.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 v0.67.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 v0.67.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 v0.67.0

encodePromise

Signature

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

Added in v0.67.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 v0.67.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 v0.67.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 v0.67.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 v0.67.0

encodeUnknownPromise

Signature

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

Added in v0.67.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 v0.67.0

filtering

FilterIssue (interface)

Signature

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

Added in v0.68.0

FilterOutput (type alias)

Signature

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

Added in v0.68.0

filter

Signature

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

Added in v0.67.0

formatting

format

Signature

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

Added in v0.67.0

guards

isSchema

Tests if a value is a Schema.

Signature

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

Added in v0.67.0

model

Schema (interface)

Signature

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

Added in v0.67.0

SchemaClass (interface)

Signature

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

Added in v0.67.0

number constructors

Finite (class)

Signature

export declare class Finite

Added in v0.67.0

Int (class)

Signature

export declare class Int

Added in v0.67.0

JsonNumber (class)

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

Signature

export declare class JsonNumber

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 v0.67.0

Negative (class)

Signature

export declare class Negative

Added in v0.67.0

NonNaN (class)

Signature

export declare class NonNaN

Added in v0.67.0

NonNegative (class)

Signature

export declare class NonNegative

Added in v0.67.0

NonPositive (class)

Signature

export declare class NonPositive

Added in v0.67.0

NumberFromString (class)

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

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

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

Signature

export declare class NumberFromString

Added in v0.67.0

Positive (class)

Signature

export declare class Positive

Added in v0.67.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, A> | undefined
) => <I, R>(self: Schema<A, I, R>) => filter<Schema<A, I, R>>

Added in v0.67.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, A> | undefined
) => <I, R>(self: Schema<A, I, R>) => filter<Schema<A, I, R>>

Added in v0.67.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, A> | undefined
) => <I, R>(self: Schema<A, I, R>) => filter<Schema<A, I, R>>

Added in v0.67.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, A> | undefined
) => <I, R>(self: Schema<A, I, R>) => filter<Schema<A, I, R>>

Added in v0.67.0

int

Signature

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

Added in v0.67.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, A> | undefined
) => <I, R>(self: Schema<A, I, R>) => filter<Schema<A, I, R>>

Added in v0.67.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, A> | undefined
) => <I, R>(self: Schema<A, I, R>) => filter<Schema<A, I, R>>

Added in v0.67.0

multipleOf

Signature

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

Added in v0.67.0

negative

Signature

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

Added in v0.67.0

nonNaN

Signature

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

Added in v0.67.0

nonNegative

Signature

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

Added in v0.67.0

nonPositive

Signature

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

Added in v0.67.0

positive

Signature

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

Added in v0.67.0

number transformations

clamp

Clamps a number between a minimum and a maximum value.

Signature

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

Added in v0.67.0

parseNumber

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

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

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

Signature

export declare const parseNumber: <A extends string, I, R>(
  self: Schema<A, I, R>
) => transformOrFail<Schema<A, I, R>, typeof Number$, never>

Added in v0.67.0

primitives

Any (class)

Signature

export declare class Any

Added in v0.67.0

BigIntFromSelf (class)

Signature

export declare class BigIntFromSelf

Added in v0.67.0

Boolean

Signature

export declare const Boolean: typeof Boolean$

Added in v0.67.0

Never (class)

Signature

export declare class Never

Added in v0.67.0

Null (class)

Signature

export declare class Null

Added in v0.67.0

Number

Signature

export declare const Number: typeof Number$

Added in v0.67.0

Object

Signature

export declare const Object: typeof Object$

Added in v0.67.0

String

Signature

export declare const String: typeof String$

Added in v0.67.0

SymbolFromSelf (class)

Signature

export declare class SymbolFromSelf

Added in v0.67.0

Undefined (class)

Signature

export declare class Undefined

Added in v0.67.0

Unknown (class)

Signature

export declare class Unknown

Added in v0.67.0

Void (class)

Signature

export declare class Void

Added in v0.67.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>) => SchemaClass<{ [K in keyof Rename<A, M>]: Rename<A, M>[K] }, 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
  ): SchemaClass<{ [K in keyof Rename<A, M>]: Rename<A, M>[K] }, I, R>
}

Added in v0.67.0

string constructors

Capitalized (class)

Signature

export declare class Capitalized

Added in v0.68.18

Char (class)

A schema representing a single character.

Signature

export declare class Char

Added in v0.67.0

Lowercased (class)

Signature

export declare class Lowercased

Added in v0.67.0

NonEmpty (class)

Signature

export declare class NonEmpty

Added in v0.67.0

Trimmed (class)

Signature

export declare class Trimmed

Added in v0.67.0

ULID (class)

Represents a Universally Unique Lexicographically Sortable Identifier (ULID).

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

Signature

export declare class ULID

Added in v0.67.0

UUID (class)

Represents a Universally Unique Identifier (UUID).

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

Signature

export declare class UUID

Added in v0.67.0

Uncapitalized (class)

Signature

export declare class Uncapitalized

Added in v0.68.18

Uppercased (class)

Signature

export declare class Uppercased

Added in v0.67.0

string filters

capitalized

Verifies that a string is capitalized.

Signature

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

Added in v0.68.18

endsWith

Signature

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

Added in v0.67.0

includes

Signature

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

Added in v0.67.0

length

Signature

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

Added in v0.67.0

lowercased

Verifies that a string is lowercased.

Signature

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

Added in v0.67.0

maxLength

Signature

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

Added in v0.67.0

minLength

Signature

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

Added in v0.67.0

nonEmpty

Signature

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

Added in v0.67.0

pattern

Signature

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

Added in v0.67.0

startsWith

Signature

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

Added in v0.67.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, A> | undefined
) => <I, R>(self: Schema<A, I, R>) => filter<Schema<A, I, R>>

Added in v0.67.0

uncapitalized

Verifies that a string is uncapitalized.

Signature

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

Added in v0.68.18

uppercased

Verifies that a string is uppercased.

Signature

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

Added in v0.67.0

string transformations

Capitalize (class)

This schema converts a string to capitalized one.

Signature

export declare class Capitalize

Added in v0.68.18

Lowercase (class)

This schema converts a string to lowercase.

Signature

export declare class Lowercase

Added in v0.67.0

Trim (class)

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

Signature

export declare class Trim

Added in v0.67.0

Uncapitalize (class)

This schema converts a string to uncapitalized one.

Signature

export declare class Uncapitalize

Added in v0.68.18

Uppercase (class)

This schema converts a string to uppercase.

Signature

export declare class Uppercase

Added in v0.67.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): SchemaClass<A, string, R>
  (options?: ParseJsonOptions): SchemaClass<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 v0.67.0

split

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

Signature

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

Added in v0.67.0

struct transformations

omit

Signature

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

Added in v0.67.0

pick

Signature

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

Added in v0.67.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 v0.67.0

symbol

PropertySignatureTypeId

Signature

export declare const PropertySignatureTypeId: typeof PropertySignatureTypeId

Added in v0.68.0

PropertySignatureTypeId (type alias)

Signature

export type PropertySignatureTypeId = typeof PropertySignatureTypeId

Added in v0.68.0

TypeId

Signature

export declare const TypeId: typeof TypeId

Added in v0.67.0

TypeId (type alias)

Signature

export type TypeId = typeof TypeId

Added in v0.67.0

refineTypeId

Signature

export declare const refineTypeId: typeof refineTypeId

Added in v0.68.8

refineTypeId (type alias)

Signature

export type refineTypeId = typeof refineTypeId

Added in v0.68.8

symbol transformations

Symbol

This schema transforms a string into a symbol.

Signature

export declare const Symbol: typeof Symbol$

Added in v0.67.0

transformations

filterEffect

Signature

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

Added in v0.68.17

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 v0.67.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 v0.67.0

type id

BetweenBigDecimalTypeId

Signature

export declare const BetweenBigDecimalTypeId: typeof BetweenBigDecimalTypeId

Added in v0.67.0

BetweenBigIntTypeId

Signature

export declare const BetweenBigIntTypeId: typeof BetweenBigIntTypeId

Added in v0.67.0

BetweenBigIntTypeId (type alias)

Signature

export type BetweenBigIntTypeId = typeof BetweenBigIntTypeId

Added in v0.67.0

BetweenDurationTypeId

Signature

export declare const BetweenDurationTypeId: typeof BetweenDurationTypeId

Added in v0.67.0

BetweenTypeId

Signature

export declare const BetweenTypeId: typeof BetweenTypeId

Added in v0.67.0

BetweenTypeId (type alias)

Signature

export type BetweenTypeId = typeof BetweenTypeId

Added in v0.67.0

BrandTypeId

Signature

export declare const BrandTypeId: typeof BrandTypeId

Added in v0.67.0

CapitalizedTypeId

Signature

export declare const CapitalizedTypeId: typeof CapitalizedTypeId

Added in v0.68.18

EndsWithTypeId

Signature

export declare const EndsWithTypeId: typeof EndsWithTypeId

Added in v0.67.0

FiniteTypeId

Signature

export declare const FiniteTypeId: typeof FiniteTypeId

Added in v0.67.0

GreaterThanBigDecimalTypeId

Signature

export declare const GreaterThanBigDecimalTypeId: typeof GreaterThanBigDecimalTypeId

Added in v0.67.0

GreaterThanBigIntTypeId

Signature

export declare const GreaterThanBigIntTypeId: typeof GreaterThanBigIntTypeId

Added in v0.67.0

GreaterThanBigIntTypeId (type alias)

Signature

export type GreaterThanBigIntTypeId = typeof GreaterThanBigIntTypeId

Added in v0.67.0

GreaterThanDurationTypeId

Signature

export declare const GreaterThanDurationTypeId: typeof GreaterThanDurationTypeId

Added in v0.67.0

GreaterThanOrEqualToBigDecimalTypeId

Signature

export declare const GreaterThanOrEqualToBigDecimalTypeId: typeof GreaterThanOrEqualToBigDecimalTypeId

Added in v0.67.0

GreaterThanOrEqualToBigIntTypeId

Signature

export declare const GreaterThanOrEqualToBigIntTypeId: typeof GreaterThanOrEqualToBigIntTypeId

Added in v0.67.0

GreaterThanOrEqualToBigIntTypeId (type alias)

Signature

export type GreaterThanOrEqualToBigIntTypeId = typeof GreaterThanOrEqualToBigIntTypeId

Added in v0.67.0

GreaterThanOrEqualToDurationTypeId

Signature

export declare const GreaterThanOrEqualToDurationTypeId: typeof GreaterThanOrEqualToDurationTypeId

Added in v0.67.0

GreaterThanOrEqualToTypeId

Signature

export declare const GreaterThanOrEqualToTypeId: typeof GreaterThanOrEqualToTypeId

Added in v0.67.0

GreaterThanOrEqualToTypeId (type alias)

Signature

export type GreaterThanOrEqualToTypeId = typeof GreaterThanOrEqualToTypeId

Added in v0.67.0

GreaterThanTypeId

Signature

export declare const GreaterThanTypeId: typeof GreaterThanTypeId

Added in v0.67.0

GreaterThanTypeId (type alias)

Signature

export type GreaterThanTypeId = typeof GreaterThanTypeId

Added in v0.67.0

IncludesTypeId

Signature

export declare const IncludesTypeId: typeof IncludesTypeId

Added in v0.67.0

InstanceOfTypeId

Signature

export declare const InstanceOfTypeId: typeof InstanceOfTypeId

Added in v0.67.0

IntTypeId

Signature

export declare const IntTypeId: typeof IntTypeId

Added in v0.67.0

IntTypeId (type alias)

Signature

export type IntTypeId = typeof IntTypeId

Added in v0.67.0

ItemsCountTypeId

Signature

export declare const ItemsCountTypeId: typeof ItemsCountTypeId

Added in v0.67.0

ItemsCountTypeId (type alias)

Signature

export type ItemsCountTypeId = typeof ItemsCountTypeId

Added in v0.67.0

JsonNumberTypeId

Signature

export declare const JsonNumberTypeId: typeof JsonNumberTypeId

Added in v0.67.0

LengthTypeId

Signature

export declare const LengthTypeId: typeof LengthTypeId

Added in v0.67.0

LengthTypeId (type alias)

Signature

export type LengthTypeId = typeof LengthTypeId

Added in v0.67.0

LessThanBigDecimalTypeId

Signature

export declare const LessThanBigDecimalTypeId: typeof LessThanBigDecimalTypeId

Added in v0.67.0

LessThanBigIntTypeId

Signature

export declare const LessThanBigIntTypeId: typeof LessThanBigIntTypeId

Added in v0.67.0

LessThanBigIntTypeId (type alias)

Signature

export type LessThanBigIntTypeId = typeof LessThanBigIntTypeId

Added in v0.67.0

LessThanDurationTypeId

Signature

export declare const LessThanDurationTypeId: typeof LessThanDurationTypeId

Added in v0.67.0

LessThanOrEqualToBigDecimalTypeId

Signature

export declare const LessThanOrEqualToBigDecimalTypeId: typeof LessThanOrEqualToBigDecimalTypeId

Added in v0.67.0

LessThanOrEqualToBigIntTypeId

Signature

export declare const LessThanOrEqualToBigIntTypeId: typeof LessThanOrEqualToBigIntTypeId

Added in v0.67.0

LessThanOrEqualToBigIntTypeId (type alias)

Signature

export type LessThanOrEqualToBigIntTypeId = typeof LessThanOrEqualToBigIntTypeId

Added in v0.67.0

LessThanOrEqualToDurationTypeId

Signature

export declare const LessThanOrEqualToDurationTypeId: typeof LessThanOrEqualToDurationTypeId

Added in v0.67.0

LessThanOrEqualToTypeId

Signature

export declare const LessThanOrEqualToTypeId: typeof LessThanOrEqualToTypeId

Added in v0.67.0

LessThanOrEqualToTypeId (type alias)

Signature

export type LessThanOrEqualToTypeId = typeof LessThanOrEqualToTypeId

Added in v0.67.0

LessThanTypeId

Signature

export declare const LessThanTypeId: typeof LessThanTypeId

Added in v0.67.0

LessThanTypeId (type alias)

Signature

export type LessThanTypeId = typeof LessThanTypeId

Added in v0.67.0

LowercasedTypeId

Signature

export declare const LowercasedTypeId: typeof LowercasedTypeId

Added in v0.67.0

MaxItemsTypeId

Signature

export declare const MaxItemsTypeId: typeof MaxItemsTypeId

Added in v0.67.0

MaxItemsTypeId (type alias)

Signature

export type MaxItemsTypeId = typeof MaxItemsTypeId

Added in v0.67.0

MaxLengthTypeId

Signature

export declare const MaxLengthTypeId: typeof MaxLengthTypeId

Added in v0.67.0

MaxLengthTypeId (type alias)

Signature

export type MaxLengthTypeId = typeof MaxLengthTypeId

Added in v0.67.0

MinItemsTypeId

Signature

export declare const MinItemsTypeId: typeof MinItemsTypeId

Added in v0.67.0

MinItemsTypeId (type alias)

Signature

export type MinItemsTypeId = typeof MinItemsTypeId

Added in v0.67.0

MinLengthTypeId

Signature

export declare const MinLengthTypeId: typeof MinLengthTypeId

Added in v0.67.0

MinLengthTypeId (type alias)

Signature

export type MinLengthTypeId = typeof MinLengthTypeId

Added in v0.67.0

MultipleOfTypeId

Signature

export declare const MultipleOfTypeId: typeof MultipleOfTypeId

Added in v0.67.0

NegativeBigDecimalTypeId

Signature

export declare const NegativeBigDecimalTypeId: typeof NegativeBigDecimalTypeId

Added in v0.67.0

NonNaNTypeId

Signature

export declare const NonNaNTypeId: typeof NonNaNTypeId

Added in v0.67.0

NonNegativeBigDecimalTypeId

Signature

export declare const NonNegativeBigDecimalTypeId: typeof NonNegativeBigDecimalTypeId

Added in v0.67.0

NonPositiveBigDecimalTypeId

Signature

export declare const NonPositiveBigDecimalTypeId: typeof NonPositiveBigDecimalTypeId

Added in v0.67.0

PatternTypeId

Signature

export declare const PatternTypeId: typeof PatternTypeId

Added in v0.67.0

PositiveBigDecimalTypeId

Signature

export declare const PositiveBigDecimalTypeId: typeof PositiveBigDecimalTypeId

Added in v0.67.0

StartsWithTypeId

Signature

export declare const StartsWithTypeId: typeof StartsWithTypeId

Added in v0.67.0

TrimmedTypeId

Signature

export declare const TrimmedTypeId: typeof TrimmedTypeId

Added in v0.67.0

ULIDTypeId

Signature

export declare const ULIDTypeId: typeof ULIDTypeId

Added in v0.67.0

UUIDTypeId

Signature

export declare const UUIDTypeId: typeof UUIDTypeId

Added in v0.67.0

UncapitalizedTypeId

Signature

export declare const UncapitalizedTypeId: typeof UncapitalizedTypeId

Added in v0.68.18

UppercasedTypeId

Signature

export declare const UppercasedTypeId: typeof UppercasedTypeId

Added in v0.67.0

ValidDateTypeId

Signature

export declare const ValidDateTypeId: typeof ValidDateTypeId

Added in v0.67.0

utils

Element (namespace)

Added in v0.68.0

Annotations (interface)

Signature

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

Added in v0.68.0

Token (type alias)

Signature

export type Token = "" | "?"

Added in v0.68.0

EnumsDefinition (type alias)

Signature

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

Added in v0.67.0

IndexSignature (namespace)

Added in v0.67.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 v0.67.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 v0.67.0

NonEmptyRecords (type alias)

Signature

export type NonEmptyRecords = array_.NonEmptyReadonlyArray<Record>

Added in v0.67.0

Record (type alias)

Signature

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

Added in v0.67.0

Records (type alias)

Signature

export type Records = ReadonlyArray<Record>

Added in v0.67.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 v0.67.0

OptionalOptions (type alias)

Signature

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

Added in v0.67.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 v0.67.0

PropertySignature (namespace)

Added in v0.67.0

Annotations (interface)

Signature

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

Added in v0.67.0

AST (type alias)

Signature

export type AST = PropertySignatureDeclaration | PropertySignatureTransformation

Added in v0.67.0

All (type alias)

Signature

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

Added in v0.67.0

Any (type alias)

Signature

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

Added in v0.67.0

Token (type alias)

Signature

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

Added in v0.67.0

Schema (namespace)

Added in v0.67.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 v0.67.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 v0.67.0

Any (type alias)

Any schema, except for never.

Signature

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

Added in v0.67.0

AnyNoContext (type alias)

Any schema with Context = never, except for never.

Signature

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

Added in v0.67.0

AsSchema (type alias)

Type-level counterpart of Schema.asSchema function.

Signature

export type AsSchema<S extends All> = Schema<Type<S>, Encoded<S>, Context<S>>

Added in v0.67.0

Context (type alias)

Signature

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

Added in v0.67.0

Encoded (type alias)

Signature

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

Added in v0.67.0

ToAsserts (type alias)

Signature

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

Added in v0.67.0

Type (type alias)

Signature

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

Added in v0.67.0

Simplify (type alias)

Signature

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

Added in v0.68.2

SimplifyMutable (type alias)

Signature

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

Added in v0.67.0

Struct (namespace)

Added in v0.67.0

Constructor (type alias)

Signature

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

Added in v0.67.0

Context (type alias)

Signature

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

Added in v0.67.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 v0.67.0

Fields (type alias)

Signature

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

Added in v0.67.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 v0.67.0

TupleType (namespace)

Added in v0.67.0

Elements (type alias)

Signature

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

Added in v0.67.0

Encoded (type alias)

Signature

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

Added in v0.67.0

Rest (type alias)

Signature

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

Added in v0.68.0

Type (type alias)

Signature

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

Added in v0.67.0

TypeLiteral (namespace)

Added in v0.67.0

Constructor (type alias)

Signature

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

Added in v0.67.0

Encoded (type alias)

Signature

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

Added in v0.67.0

Type (type alias)

Signature

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

Added in v0.67.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 v0.67.0

element

Signature

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

Added in v0.68.0

encodedBoundSchema

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

Signature

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

Added in v0.67.17

encodedSchema

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

Signature

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

Added in v0.67.0

optionalElement

Signature

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

Added in v0.67.0

tag

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

Signature

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

Example

import { Schema } from "@effect/schema"

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

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

Added in v0.67.14

typeSchema

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

Signature

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

Added in v0.67.0

validation

asserts

By default the option exact is set to true.

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 v0.67.0

is

By default the option exact is set to true.

Signature

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

Added in v0.67.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 v0.67.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 v0.67.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 v0.67.0

validatePromise

Signature

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

Added in v0.67.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 v0.67.0