flip<S>Swaps the decoded and encoded sides of a schema.
When to use
Use to invert a schema transformation direction.
Details
Calling flip twice returns the original schema.
Example (Flipping a number-from-string schema)
import { Schema } from "effect"
// NumberFromString: decodes string → number
const flipped = Schema.flip(Schema.NumberFromString)
// flipped: decodes number → stringexport interface interface flip<S extends Top>Swaps the decoded and encoded sides of a schema.
When to use
Use to invert a schema transformation direction.
Details
Calling flip twice returns the original schema.
Example (Flipping a number-from-string schema)
import { Schema } from "effect"
// NumberFromString: decodes string → number
const flipped = Schema.flip(Schema.NumberFromString)
// flipped: decodes number → string
Type-level representation returned by
flip
.
flip<function (type parameter) S in flip<S extends Top>S extends Top> extends
interface BottomLazy<out Ast extends SchemaAST.AST, out Rebuild extends Top, in out TypeParameters extends ReadonlyArray<Constraint> = readonly [], out TypeMutability extends Mutability = "readonly", out TypeOptionality extends Optionality = "required", out TypeConstructorDefault extends ConstructorDefault = "no-default", out EncodedMutability extends Mutability = "readonly", out EncodedOptionality extends Optionality = "required">Lazy Bottom variant for schema implementations that compute their public
views on demand.
When to use
Use as an implementation base for schema interfaces that must expose
Bottom behavior without forcing TypeScript to eagerly evaluate expensive
Type, Encoded, or service views.
Details
The laziness is purely type-level; runtime behavior is unchanged.
BottomLazy keeps the structural operations inherited from Bottom, but
erases the expensive schema views to unknown. Concrete schema interfaces can
then redeclare the precise views they expose. This keeps wide schemas such as
Struct and Union cheaper when generic code reads a single view, while
preserving their exact public types.
BottomLazy<
import SchemaASTSchemaAST.type AST = SchemaAST.Declaration | SchemaAST.Null | SchemaAST.Undefined | SchemaAST.Void | SchemaAST.Never | SchemaAST.Unknown | SchemaAST.Any | SchemaAST.String | SchemaAST.Number | SchemaAST.Boolean | SchemaAST.BigInt | SchemaAST.Symbol | SchemaAST.Literal | SchemaAST.UniqueSymbol | SchemaAST.ObjectKeyword | SchemaAST.Enum | SchemaAST.TemplateLiteral | SchemaAST.Arrays | SchemaAST.Objects | SchemaAST.Union<...> | SchemaAST.SuspendDiscriminated union of all AST node types.
Details
Every Schema has an .ast property of this type. Use the guard functions
(
isString
,
isObjects
, etc.) to narrow to a specific variant,
then access variant-specific fields.
- All variants share the
Base
fields:
annotations, checks,
encoding, context.
- Discriminate on the
_tag field (e.g. "String", "Objects", "Union").
AST,
interface flip<S extends Top>Swaps the decoded and encoded sides of a schema.
When to use
Use to invert a schema transformation direction.
Details
Calling flip twice returns the original schema.
Example (Flipping a number-from-string schema)
import { Schema } from "effect"
// NumberFromString: decodes string → number
const flipped = Schema.flip(Schema.NumberFromString)
// flipped: decodes number → string
Type-level representation returned by
flip
.
flip<function (type parameter) S in flip<S extends Top>S>,
interface ReadonlyArray<T>ReadonlyArray<Constraint>,
function (type parameter) S in flip<S extends Top>S["~encoded.mutability"],
function (type parameter) S in flip<S extends Top>S["~encoded.optionality"],
type ConstructorDefault =
| "no-default"
| "with-default"
Whether a schema field has a constructor default value.
ConstructorDefault,
function (type parameter) S in flip<S extends Top>S["~type.mutability"],
function (type parameter) S in flip<S extends Top>S["~type.optionality"]
>
{
readonly "Type": function (type parameter) S in flip<S extends Top>S["Encoded"]
readonly "Encoded": function (type parameter) S in flip<S extends Top>S["Type"]
readonly "DecodingServices": function (type parameter) S in flip<S extends Top>S["EncodingServices"]
readonly "EncodingServices": function (type parameter) S in flip<S extends Top>S["DecodingServices"]
readonly "~type.make.in": function (type parameter) S in flip<S extends Top>S["Encoded"]
readonly "~type.make": function (type parameter) S in flip<S extends Top>S["Encoded"]
readonly "Iso": function (type parameter) S in flip<S extends Top>S["Encoded"]
readonly [const FlipTypeId: "~effect/Schema/flip"FlipTypeId]: typeof const FlipTypeId: "~effect/Schema/flip"FlipTypeId
readonly flip<S extends Top>.schema: S extends Topschema: function (type parameter) S in flip<S extends Top>S
}
function function isFlip$(
schema: Top
): schema is flip<any>
isFlip$(schema: Top(parameter) schema: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<unknown, any>) => Top;
annotateKey: (annotations: Annotations.Key<unknown>) => Top;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Top;
rebuild: (ast: SchemaAST.AST) => Top;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
schema: Top): schema: Topschema is interface flip<S extends Top>Swaps the decoded and encoded sides of a schema.
When to use
Use to invert a schema transformation direction.
Details
Calling flip twice returns the original schema.
Example (Flipping a number-from-string schema)
import { Schema } from "effect"
// NumberFromString: decodes string → number
const flipped = Schema.flip(Schema.NumberFromString)
// flipped: decodes number → string
Type-level representation returned by
flip
.
flip<any> {
return import PredicatePredicate.hasProperty(schema: Top(parameter) schema: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<unknown, any>) => Top;
annotateKey: (annotations: Annotations.Key<unknown>) => Top;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Top;
rebuild: (ast: SchemaAST.AST) => Top;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
schema, const FlipTypeId: "~effect/Schema/flip"FlipTypeId) && schema: Topschema[const FlipTypeId: "~effect/Schema/flip"FlipTypeId] === const FlipTypeId: "~effect/Schema/flip"FlipTypeId
}
/**
* Swaps the decoded and encoded sides of a schema.
*
* **When to use**
*
* Use to invert a schema transformation direction.
*
* **Details**
*
* Calling `flip` twice returns the original schema.
*
* **Example** (Flipping a number-from-string schema)
*
* ```ts
* import { Schema } from "effect"
*
* // NumberFromString: decodes string → number
* const flipped = Schema.flip(Schema.NumberFromString)
* // flipped: decodes number → string
* ```
*
* @category transforming
* @since 4.0.0
*/
export function function flip<S extends Top>(
schema: S
): S extends flip<infer F>
? F["Rebuild"]
: flip<S>
Swaps the decoded and encoded sides of a schema.
When to use
Use to invert a schema transformation direction.
Details
Calling flip twice returns the original schema.
Example (Flipping a number-from-string schema)
import { Schema } from "effect"
// NumberFromString: decodes string → number
const flipped = Schema.flip(Schema.NumberFromString)
// flipped: decodes number → string
flip<function (type parameter) S in flip<S extends Top>(schema: S): S extends flip<infer F> ? F["Rebuild"] : flip<S>S extends Top>(schema: S extends Topschema: function (type parameter) S in flip<S extends Top>(schema: S): S extends flip<infer F> ? F["Rebuild"] : flip<S>S): function (type parameter) S in flip<S extends Top>(schema: S): S extends flip<infer F> ? F["Rebuild"] : flip<S>S extends interface flip<S extends Top>Swaps the decoded and encoded sides of a schema.
When to use
Use to invert a schema transformation direction.
Details
Calling flip twice returns the original schema.
Example (Flipping a number-from-string schema)
import { Schema } from "effect"
// NumberFromString: decodes string → number
const flipped = Schema.flip(Schema.NumberFromString)
// flipped: decodes number → string
Type-level representation returned by
flip
.
flip<infer function (type parameter) FF> ? function (type parameter) FF["Rebuild"] : interface flip<S extends Top>Swaps the decoded and encoded sides of a schema.
When to use
Use to invert a schema transformation direction.
Details
Calling flip twice returns the original schema.
Example (Flipping a number-from-string schema)
import { Schema } from "effect"
// NumberFromString: decodes string → number
const flipped = Schema.flip(Schema.NumberFromString)
// flipped: decodes number → string
Type-level representation returned by
flip
.
flip<function (type parameter) S in flip<S extends Top>(schema: S): S extends flip<infer F> ? F["Rebuild"] : flip<S>S>
export function function flip<S extends Top>(
schema: S
): S extends flip<infer F>
? F["Rebuild"]
: flip<S>
Swaps the decoded and encoded sides of a schema.
When to use
Use to invert a schema transformation direction.
Details
Calling flip twice returns the original schema.
Example (Flipping a number-from-string schema)
import { Schema } from "effect"
// NumberFromString: decodes string → number
const flipped = Schema.flip(Schema.NumberFromString)
// flipped: decodes number → string
flip<function (type parameter) S in flip<S extends Top>(schema: S): flip<S>S extends Top>(schema: S extends Topschema: function (type parameter) S in flip<S extends Top>(schema: S): flip<S>S): interface flip<S extends Top>Swaps the decoded and encoded sides of a schema.
When to use
Use to invert a schema transformation direction.
Details
Calling flip twice returns the original schema.
Example (Flipping a number-from-string schema)
import { Schema } from "effect"
// NumberFromString: decodes string → number
const flipped = Schema.flip(Schema.NumberFromString)
// flipped: decodes number → string
Type-level representation returned by
flip
.
flip<function (type parameter) S in flip<S extends Top>(schema: S): flip<S>S> {
if (function isFlip$(
schema: Top
): schema is flip<any>
isFlip$(schema: S extends Topschema)) {
return schema: S & flip<any>schema.flip<any>.schema: anyschema.rebuild(import SchemaASTSchemaAST.const flip: anySwaps the decode and encode directions of an AST's
Encoding
chain.
Details
After flipping, what was decoding becomes encoding and vice versa. This is
the core operation behind Schema.encode — encoding a value is decoding
with a flipped SchemaAST.
- Memoized: same input reference → same output reference.
- Recursively walks composite nodes.
flip(schema: S & flip<any>schema.Bottom<out T, out E, out RD, out RE, out Ast extends SchemaAST.AST, out Rebuild extends Top, out TypeMakeIn = T, out Iso = T, in out TypeParameters extends ReadonlyArray<Constraint> = readonly [], out TypeMake = TypeMakeIn, out TypeMutability extends Mutability = "readonly", out TypeOptionality extends Optionality = "required", out TypeConstructorDefault extends ConstructorDefault = "no-default", out EncodedMutability extends Mutability = "readonly", out EncodedOptionality extends Optionality = "required">["ast"]: SchemaAST.ASTast))
}
return const make: <S extends Constraint>(
ast: S["ast"],
options?: object
) => S
Creates a schema from an AST (Abstract Syntax Tree) node.
Details
This is the fundamental constructor for all schemas in the Effect Schema
library. It takes an AST node and wraps it in a fully-typed schema that
preserves all type information and provides the complete schema API.
The make function is used internally to create all primitive schemas like
String, Number, Boolean, etc., as well as more complex schemas. It's
the bridge between the untyped AST representation and the strongly-typed
schema.
make(import SchemaASTSchemaAST.const flip: anySwaps the decode and encode directions of an AST's
Encoding
chain.
Details
After flipping, what was decoding becomes encoding and vice versa. This is
the core operation behind Schema.encode — encoding a value is decoding
with a flipped SchemaAST.
- Memoized: same input reference → same output reference.
- Recursively walks composite nodes.
flip(schema: S extends Topschema.Bottom<unknown, unknown, unknown, unknown, AST, Top, unknown, unknown, any, unknown, Mutability, Optionality, ConstructorDefault, Mutability, Optionality>["ast"]: SchemaAST.ASTast), { [const FlipTypeId: "~effect/Schema/flip"FlipTypeId]: const FlipTypeId: "~effect/Schema/flip"FlipTypeId, schema: S extends Topschema })
}