Skip to content

ParseResult

60 exports Added in v3.10.0 Source

Constructors

fail

Added in v3.10.0 Source

Signature

declare const fail: (issue: ParseIssue) => Either.Either<never, ParseIssue>;

fromOption

Added in v3.10.0 Source

Signature

declare const fromOption: {
  (onNone: () => ParseIssue): <A>(self: Option<A>) => Either<A, ParseIssue>;
  <A>(self: Option<A>, onNone: () => ParseIssue): Either<A, ParseIssue>;
};

parseError

Added in v3.10.0 Source

Signature

declare function parseError(issue: ParseIssue): ParseError;

succeed

Added in v3.10.0 Source

Signature

declare const succeed: <A>(a: A) => Either.Either<A, ParseIssue>;

Decoding

decode

Added in v3.10.0 Source

Signature

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

decodeEither

Added in v3.10.0 Source

Signature

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

decodeOption

Added in v3.10.0 Source

Signature

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

decodePromise

Added in v3.10.0 Source

Signature

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

decodeSync

Added in v3.10.0 Source

Signature

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

decodeUnknown

Added in v3.10.0 Source

Signature

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

Signature

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

Signature

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

Signature

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

Signature

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

Encoding

encode

Added in v3.10.0 Source

Signature

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

encodeEither

Added in v3.10.0 Source

Signature

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

encodeOption

Added in v3.10.0 Source

Signature

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

encodePromise

Added in v3.10.0 Source

Signature

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

encodeSync

Added in v3.10.0 Source

Signature

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

encodeUnknown

Added in v3.10.0 Source

Signature

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

Signature

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

Signature

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

Signature

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

Signature

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

Formatting

ArrayFormatter

Added in v3.10.0 Source

Signature

declare const ArrayFormatter: ParseResultFormatter<Array<ArrayFormatterIssue>>;

ParseResultFormatter interface

Added in v3.10.0 Source

Signature

interface ParseResultFormatter<A> {
  readonly formatError: (error: ParseError) => Effect<A>;
  readonly formatErrorSync: (error: ParseError) => A;
  readonly formatIssue: (issue: ParseIssue) => Effect<A>;
  readonly formatIssueSync: (issue: ParseIssue) => A;
}

TreeFormatter

Added in v3.10.0 Source

Signature

declare const TreeFormatter: ParseResultFormatter<string>;

Guards

isComposite

Added in v3.10.0 Source

Returns true if the value is a Composite.

Signature

declare const isComposite: (issue: ParseIssue) => issue is Composite;

Model

ArrayFormatterIssue interface

Added in v3.10.0 Source

Represents an issue returned by the ArrayFormatter formatter.

Signature

interface ArrayFormatterIssue {
  readonly _tag: "Composite" | "Pointer" | "Unexpected" | "Missing" | "Refinement" | "Transformation" | "Type" | "Forbidden";
  readonly message: string;
  readonly path: readonly Array<PropertyKey>;
}

Composite

Added in v3.10.0 Source

Error that contains multiple issues.

Signature

declare class Composite {
  constructor(ast: AST, actual: unknown, issues: SingleOrNonEmpty<ParseIssue>, output?: unknown);
  readonly _tag: "Composite";
  readonly actual: unknown;
  readonly ast: AST;
  readonly issues: SingleOrNonEmpty<ParseIssue>;
  readonly output?: unknown;
}

Forbidden

Added in v3.10.0 Source

The Forbidden variant of the ParseIssue type represents a forbidden operation, such as when encountering an Effect that is not allowed to execute (e.g., using runSync).

Signature

declare class Forbidden {
  constructor(ast: AST, actual: unknown, message?: string);
  readonly _tag: "Forbidden";
  readonly actual: unknown;
  readonly ast: AST;
  readonly message?: string;
}

Missing

Added in v3.10.0 Source

Error that occurs when a required key or index is missing.

Signature

declare class Missing {
  constructor(ast: Type, message?: string);
  readonly _tag: "Missing";
  readonly actual: undefined;
  readonly ast: Type;
  readonly message?: string;
}

ParseIssue type

Added in v3.10.0 Source

ParseIssue is a type that represents the different types of errors that can occur when decoding/encoding a value.

Signature

type ParseIssue =
  | Type
  | Missing
  | Unexpected
  | Forbidden
  | Pointer
  | Refinement
  | Transformation
  | Composite;

Path type

Added in v3.10.0 Source

Signature

type Path = SingleOrNonEmpty<PropertyKey>;

Pointer

Added in v3.10.0 Source

Signature

declare class Pointer {
  constructor(path: Path, actual: unknown, issue: ParseIssue);
  readonly _tag: "Pointer";
  readonly actual: unknown;
  readonly issue: ParseIssue;
  readonly path: Path;
}

Refinement

Added in v3.10.0 Source

Error that occurs when a refinement has an error.

Signature

declare class Refinement {
  constructor(ast: Refinement, actual: unknown, kind: "From" | "Predicate", issue: ParseIssue);
  readonly _tag: "Refinement";
  readonly actual: unknown;
  readonly ast: Refinement;
  readonly issue: ParseIssue;
  readonly kind: "From" | "Predicate";
}

SingleOrNonEmpty type

Added in v3.10.0 Source

Signature

type SingleOrNonEmpty<A> = A | Arr.NonEmptyReadonlyArray<A>;

Transformation

Added in v3.10.0 Source

Error that occurs when a transformation has an error.

Signature

declare class Transformation {
  constructor(
    ast: Transformation,
    actual: unknown,
    kind: "Encoded" | "Transformation" | "Type",
    issue: ParseIssue,
  );
  readonly _tag: "Transformation";
  readonly actual: unknown;
  readonly ast: Transformation;
  readonly issue: ParseIssue;
  readonly kind: "Encoded" | "Transformation" | "Type";
}

Type

Added in v3.10.0 Source

The Type variant of the ParseIssue type represents an error that occurs when the actual value is not of the expected type. The ast field specifies the expected type, and the actual field contains the value that caused the error.

Signature

declare class Type {
  constructor(ast: AST, actual: unknown, message?: string);
  readonly _tag: "Type";
  readonly actual: unknown;
  readonly ast: AST;
  readonly message?: string;
}

Unexpected

Added in v3.10.0 Source

Error that occurs when an unexpected key or index is present.

Signature

declare class Unexpected {
  constructor(actual: unknown, message?: string);
  readonly _tag: "Unexpected";
  readonly actual: unknown;
  readonly message?: string;
}

Optimisation

Signature

declare function eitherOrUndefined<A, E, R>(self: Effect<A, E, R>): Either<A, E> | undefined;

flatMap

Added in v3.10.0 Source

Signature

declare const flatMap: {
  <A, B, E1, R1>(
    f: (a: A) => Effect<B, E1, R1>,
  ): <E, R>(self: Effect<A, E, R>) => Effect<B, E1 | E, R1 | R>;
  <A, E, R, B, E1, R1>(
    self: Effect<A, E, R>,
    f: (a: A) => Effect<B, E1, R1>,
  ): Effect<B, E | E1, R | R1>;
};

map

Added in v3.10.0 Source

Signature

declare const map: {
  <A, B>(f: (a: A) => B): <E, R>(self: Effect<A, E, R>) => Effect<B, E, R>;
  <A, E, R, B>(self: Effect<A, E, R>, f: (a: A) => B): Effect<B, E, R>;
};

mapBoth

Added in v3.10.0 Source

Signature

declare const mapBoth: {
  <E, E2, A, A2>(options: {
    readonly onFailure: (e: E) => E2;
    readonly onSuccess: (a: A) => A2;
  }): <R>(self: Effect<A, E, R>) => Effect<A2, E2, R>;
  <A, E, R, E2, A2>(
    self: Effect<A, E, R>,
    options: {
      readonly onFailure: (e: E) => E2;
      readonly onSuccess: (a: A) => A2;
    },
  ): Effect<A2, E2, R>;
};

mapError

Added in v3.10.0 Source

Signature

declare const mapError: {
  <E, E2>(f: (e: E) => E2): <A, R>(self: Effect<A, E, R>) => Effect<A, E2, R>;
  <A, E, R, E2>(self: Effect<A, E, R>, f: (e: E) => E2): Effect<A, E2, R>;
};

orElse

Added in v3.10.0 Source

Signature

declare const orElse: {
  <E, A2, E2, R2>(
    f: (e: E) => Effect<A2, E2, R2>,
  ): <A, R>(self: Effect<A, E, R>) => Effect<A2 | A, E2, R2 | R>;
  <A, E, R, A2, E2, R2>(
    self: Effect<A, E, R>,
    f: (e: E) => Effect<A2, E2, R2>,
  ): Effect<A | A2, E2, R | R2>;
};

Other

Signature

type DeclarationDecodeUnknown<Out, R> = (
  u: unknown,
  options: AST.ParseOptions,
  ast: AST.Declaration,
) => Effect.Effect<Out, ParseIssue, R>;

DecodeUnknown type

Added in v3.10.0 Source

Signature

type DecodeUnknown<Out, R> = (
  u: unknown,
  options?: AST.ParseOptions,
) => Effect.Effect<Out, ParseIssue, R>;

isParseError

Added in v3.10.0 Source

Signature

declare function isParseError(u: unknown): u is ParseError;

ParseError

Added in v3.10.0 Source

Signature

declare class ParseError extends YieldableError<this> & {
  readonly _tag: "ParseError";
} & Readonly<{
  readonly issue: ParseIssue;
}> {
  constructor(args: {
    readonly issue: ParseIssue;
  });
  readonly [ParseErrorTypeId]: symbol;
  message: string;
  [NodeInspectSymbol](): {
    _id: string;
    message: string;
  };
  toJSON(): {
    _id: string;
    message: string;
  };
  toString(): string;
}

Signature

declare const try: <A>(options: {
  catch: (e: unknown) => ParseIssue;
  try: LazyArg<A>;
}) => Either.Either<A, ParseIssue>

Type Id

Signature

declare const ParseErrorTypeId: unique symbol;

ParseErrorTypeId type

Added in v3.10.0 Source

Signature

type ParseErrorTypeId = typeof ParseErrorTypeId;

Validation

asserts

Added in v3.10.0 Source

By default the option exact is set to true.

Signature

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

is

Added in v3.10.0 Source

By default the option exact is set to true.

Signature

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

validate

Added in v3.10.0 Source

Signature

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

validateEither

Added in v3.10.0 Source

Signature

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

validateOption

Added in v3.10.0 Source

Signature

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

Signature

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

validateSync

Added in v3.10.0 Source

Signature

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