FuncType - v1.21.0
    Preparing search index...

    Variable Decoder

    Decoder: { _tag: "Decoder" } & {
        array: <A>(inner: Decoder<A>) => Decoder<A[]>;
        boolean: Decoder<boolean>;
        either: {
            discriminated: <L, R>(
                config: { leftTag: string; rightTag: string; tag: string },
                left: Decoder<L>,
                right: Decoder<R>,
            ) => Decoder<Either<L, R>>;
            envelope: <L, R>(
                shape: { err: Decoder<L>; ok: Decoder<R> },
            ) => Decoder<Either<L, R>>;
        };
        fromThrowing: <A>(parse: (raw: unknown) => A) => Decoder<A>;
        list: <A>(inner: Decoder<A>) => Decoder<List<A>>;
        map: <V>(inner: Decoder<V>) => Decoder<Map<string, V>>;
        nullable: <A>(inner: Decoder<A>) => Decoder<A | null>;
        number: Decoder<number>;
        object: <T extends Record<string, unknown>>(
            shape: { [K in string | number | symbol]: Decoder<T[K]> },
        ) => Decoder<T>;
        option: <A>(inner: Decoder<A>) => Decoder<Option<A>>;
        string: Decoder<string>;
        tagged: {
            either: <L, R>(
                left: Decoder<L>,
                right: Decoder<R>,
            ) => Decoder<Either<L, R>>;
            list: <A>(inner: Decoder<A>) => Decoder<List<A>>;
            map: <V>(inner: Decoder<V>) => Decoder<Map<string, V>>;
            obj: <T extends Record<string, unknown>>(
                shape: { [K in string | number | symbol]: Decoder<T[K]> },
            ) => Decoder<T>;
            option: <A>(inner: Decoder<A>) => Decoder<Option<A>>;
            try: <A>(inner: Decoder<A>) => Decoder<Try<A>>;
        };
        unknown: Decoder<unknown>;
    }

    Decoder namespace: combinators for converting unknown into typed values.

    • Decoder.string / .number / .boolean / .unknown / .nullable(inner) — leaf primitives
    • Decoder.fromThrowing(parse) — adapt a throwing parser (Zod .parse); a throw becomes a leaf error
    • Decoder.option(inner) — null-bias Option (null → None, else inner → Some)
    • Decoder.either.envelope({ok, err}) / .discriminated({...}, l, r) — Either variants
    • Decoder.list(inner) / .array(inner) / .map(inner) / .object(shape) — composites; accumulate child failures
    • Decoder.tagged.option/either/try/list/map/obj(inner?) — round-trip the {_tag, value} shape used by functype's built-in .toJSON() (for functype-to-functype services)

    Type Declaration

    • Readonly_tag: "Decoder"
    • array: <A>(inner: Decoder<A>) => Decoder<A[]>
    • boolean: Decoder<boolean>
    • either: {
          discriminated: <L, R>(
              config: { leftTag: string; rightTag: string; tag: string },
              left: Decoder<L>,
              right: Decoder<R>,
          ) => Decoder<Either<L, R>>;
          envelope: <L, R>(
              shape: { err: Decoder<L>; ok: Decoder<R> },
          ) => Decoder<Either<L, R>>;
      }
      • discriminated: <L, R>(
            config: { leftTag: string; rightTag: string; tag: string },
            left: Decoder<L>,
            right: Decoder<R>,
        ) => Decoder<Either<L, R>>
      • envelope: <L, R>(shape: { err: Decoder<L>; ok: Decoder<R> }) => Decoder<Either<L, R>>
    • fromThrowing: <A>(parse: (raw: unknown) => A) => Decoder<A>

      Adapts a parser that throws on bad input (Zod's schema.parse, a hand-written check) into a Decoder. A throw becomes a DecoderError leaf whose cause is the thrown value.

      Http.get("/api/user", { decode: Decoder.fromThrowing((raw) => UserSchema.parse(raw)) })
      
    • list: <A>(inner: Decoder<A>) => Decoder<List<A>>
    • map: <V>(inner: Decoder<V>) => Decoder<Map<string, V>>
    • nullable: <A>(inner: Decoder<A>) => Decoder<A | null>
    • number: Decoder<number>
    • object: <T extends Record<string, unknown>>(
          shape: { [K in string | number | symbol]: Decoder<T[K]> },
      ) => Decoder<T>
    • option: <A>(inner: Decoder<A>) => Decoder<Option<A>>
    • string: Decoder<string>
    • tagged: {
          either: <L, R>(
              left: Decoder<L>,
              right: Decoder<R>,
          ) => Decoder<Either<L, R>>;
          list: <A>(inner: Decoder<A>) => Decoder<List<A>>;
          map: <V>(inner: Decoder<V>) => Decoder<Map<string, V>>;
          obj: <T extends Record<string, unknown>>(
              shape: { [K in string | number | symbol]: Decoder<T[K]> },
          ) => Decoder<T>;
          option: <A>(inner: Decoder<A>) => Decoder<Option<A>>;
          try: <A>(inner: Decoder<A>) => Decoder<Try<A>>;
      }
    • unknown: Decoder<unknown>