Codec<T, E, RD, RE>Namespace of type-level helpers for Codec.
export declare namespace Codec {
/**
* Extracts the encoded (`Encoded`) type from a schema.
*
* **Example** (Extracting the encoded type)
*
* ```ts
* import { Schema } from "effect"
*
* const schema = Schema.NumberFromString
* type Enc = Schema.Codec.Encoded<typeof schema>
* // string
* ```
*
* @category utility types
* @since 3.10.0
*/
export type type Codec<out T, out E = T, out RD = never, out RE = never>.Encoded<S> = S extends {
readonly Encoded: infer E;
} ? E : never
Extracts the encoded (Encoded) type from a schema.
Example (Extracting the encoded type)
import { Schema } from "effect"
const schema = Schema.NumberFromString
type Enc = Schema.Codec.Encoded<typeof schema>
// string
Encoded<function (type parameter) S in type Codec<out T, out E = T, out RD = never, out RE = never>.Encoded<S>S> = function (type parameter) S in type Codec<out T, out E = T, out RD = never, out RE = never>.Encoded<S>S extends { readonly "Encoded": infer function (type parameter) EE } ? function (type parameter) EE : never
/**
* Extracts the Effect services required during *decoding* from a schema.
*
* **Example** (Checking decoding service requirements)
*
* ```ts
* import { Schema } from "effect"
*
* const schema = Schema.String
* type RD = Schema.Codec.DecodingServices<typeof schema>
* // never
* ```
*
* @category utility types
* @since 4.0.0
*/
export type type Codec<out T, out E = T, out RD = never, out RE = never>.DecodingServices<S> = S extends {
readonly DecodingServices: infer R;
} ? R : never
Extracts the Effect services required during decoding from a schema.
Example (Checking decoding service requirements)
import { Schema } from "effect"
const schema = Schema.String
type RD = Schema.Codec.DecodingServices<typeof schema>
// never
DecodingServices<function (type parameter) S in type Codec<out T, out E = T, out RD = never, out RE = never>.DecodingServices<S>S> = function (type parameter) S in type Codec<out T, out E = T, out RD = never, out RE = never>.DecodingServices<S>S extends { readonly "DecodingServices": infer function (type parameter) RR } ? function (type parameter) RR : never
/**
* Extracts the Effect services required during *encoding* from a schema.
*
* **Example** (Checking encoding service requirements)
*
* ```ts
* import { Schema } from "effect"
*
* const schema = Schema.String
* type RE = Schema.Codec.EncodingServices<typeof schema>
* // never
* ```
*
* @category utility types
* @since 4.0.0
*/
export type type Codec<out T, out E = T, out RD = never, out RE = never>.EncodingServices<S> = S extends {
readonly EncodingServices: infer R;
} ? R : never
Extracts the Effect services required during encoding from a schema.
Example (Checking encoding service requirements)
import { Schema } from "effect"
const schema = Schema.String
type RE = Schema.Codec.EncodingServices<typeof schema>
// never
EncodingServices<function (type parameter) S in type Codec<out T, out E = T, out RD = never, out RE = never>.EncodingServices<S>S> = function (type parameter) S in type Codec<out T, out E = T, out RD = never, out RE = never>.EncodingServices<S>S extends { readonly "EncodingServices": infer function (type parameter) RR } ? function (type parameter) RR : never
}
/**
* A schema that tracks the decoded type `T`, the encoded type `E`, and the
* Effect services required during decoding (`RD`) and encoding (`RE`).
*
* **Details**
*
* Use `Codec<T, E, RD, RE>` when you need to preserve full type information
* about a schema — both what it decodes to and what it serializes from/to.
* Most concrete schemas produced by this module implement `Codec`.
*
* For APIs that only need one direction, prefer the narrower views:
* - {@link Decoder}`<T, RD>` — decode-only
* - {@link Encoder}`<E, RE>` — encode-only
* - {@link Schema}`<T>` — type-only (no encoded representation)
*
* **Example** (Accepting a codec that decodes to `number` from `string`)
*
* ```ts
* import { Schema } from "effect"
*
* declare function serialize<T>(codec: Schema.Codec<T, string>): string
*
* serialize(Schema.NumberFromString) // ok — decodes number, encoded as string
* ```
*
* @see {@link Codec.Encoded} — extract the encoded type
* @see {@link Codec.DecodingServices} — extract required decoding services
* @see {@link Codec.EncodingServices} — extract required encoding services
* @see {@link revealCodec} — helper to make TypeScript infer the full Codec type
*
* @category models
* @since 4.0.0
*/
export interface interface Codec<out T, out E = T, out RD = never, out RE = never>Namespace of type-level helpers for
Codec
.
A schema that tracks the decoded type T, the encoded type E, and the
Effect services required during decoding (RD) and encoding (RE).
Details
Use Codec<T, E, RD, RE> when you need to preserve full type information
about a schema — both what it decodes to and what it serializes from/to.
Most concrete schemas produced by this module implement Codec.
For APIs that only need one direction, prefer the narrower views:
Decoder
<T, RD> — decode-only
Encoder
<E, RE> — encode-only
Schema
<T> — type-only (no encoded representation)
Example (Accepting a codec that decodes to number from string)
import { Schema } from "effect"
declare function serialize<T>(codec: Schema.Codec<T, string>): string
serialize(Schema.NumberFromString) // ok — decodes number, encoded as string
Codec<out function (type parameter) T in Codec<out T, out E = T, out RD = never, out RE = never>T, out function (type parameter) E in Codec<out T, out E = T, out RD = never, out RE = never>E = function (type parameter) T in Codec<out T, out E = T, out RD = never, out RE = never>T, out function (type parameter) RD in Codec<out T, out E = T, out RD = never, out RE = never>RD = never, out function (type parameter) RE in Codec<out T, out E = T, out RD = never, out RE = never>RE = never> extends interface Schema<out T>Namespace of type-level helpers for
Schema
.
A typed view of a schema that tracks only the decoded (output) type T.
Details
Use Schema<T> as a constraint when you want to accept "any schema that
decodes to T" and do not need to know or constrain the encoded
representation, required services, or any other type parameters.
This is a structural interface — concrete schema values are produced by the
constructors in this module (e.g.
Struct
,
String
,
Number
).
When you also need the encoded type or service requirements, use
Codec
.
Example (Accepting any schema decoding to string)
import { Schema } from "effect"
declare function print(schema: Schema.Schema<string>): void
print(Schema.String) // ok
print(Schema.NonEmptyString) // ok
Schema<function (type parameter) T in Codec<out T, out E = T, out RD = never, out RE = never>T> {
readonly "Encoded": function (type parameter) E in Codec<out T, out E = T, out RD = never, out RE = never>E
readonly "DecodingServices": function (type parameter) RD in Codec<out T, out E = T, out RD = never, out RE = never>RD
readonly "EncodingServices": function (type parameter) RE in Codec<out T, out E = T, out RD = never, out RE = never>RE
readonly "Rebuild": interface Codec<out T, out E = T, out RD = never, out RE = never>Namespace of type-level helpers for
Codec
.
A schema that tracks the decoded type T, the encoded type E, and the
Effect services required during decoding (RD) and encoding (RE).
Details
Use Codec<T, E, RD, RE> when you need to preserve full type information
about a schema — both what it decodes to and what it serializes from/to.
Most concrete schemas produced by this module implement Codec.
For APIs that only need one direction, prefer the narrower views:
Decoder
<T, RD> — decode-only
Encoder
<E, RE> — encode-only
Schema
<T> — type-only (no encoded representation)
Example (Accepting a codec that decodes to number from string)
import { Schema } from "effect"
declare function serialize<T>(codec: Schema.Codec<T, string>): string
serialize(Schema.NumberFromString) // ok — decodes number, encoded as string
Codec<function (type parameter) T in Codec<out T, out E = T, out RD = never, out RE = never>T, function (type parameter) E in Codec<out T, out E = T, out RD = never, out RE = never>E, function (type parameter) RD in Codec<out T, out E = T, out RD = never, out RE = never>RD, function (type parameter) RE in Codec<out T, out E = T, out RD = never, out RE = never>RE>
}