NullishOr<S>Type-level representation returned by NullishOr.
export interface interface NullishOr<S extends Constraint>Type-level representation returned by
NullishOr
.
Creates a union schema of S | null | undefined.
NullishOr<function (type parameter) S in NullishOr<S extends Constraint>S extends Constraint> extends interface Union<Members extends ReadonlyArray<Constraint>>Creates a union schema from an array of member schemas. Members are tested in
order; the first match is returned.
Details
Optionally, specify mode:
"anyOf" (default) — matches if any member matches.
"oneOf" — matches if exactly one member matches.
Example (Defining a string or number union)
import { Schema } from "effect"
const schema = Schema.Union([Schema.String, Schema.Number])
Schema.decodeUnknownSync(schema)("hello") // "hello"
Schema.decodeUnknownSync(schema)(42) // 42
Type-level representation returned by
Union
.
Union<readonly [function (type parameter) S in NullishOr<S extends Constraint>S, Null, Undefined]> {
readonly "Rebuild": interface NullishOr<S extends Constraint>Type-level representation returned by
NullishOr
.
Creates a union schema of S | null | undefined.
NullishOr<function (type parameter) S in NullishOr<S extends Constraint>S>
}
interface NullishOrLambda extends Lambda {
<function (type parameter) S in <S extends Constraint>(self: S): NullishOr<S>S extends Constraint>(self: S extends Constraintself: function (type parameter) S in <S extends Constraint>(self: S): NullishOr<S>S): interface NullishOr<S extends Constraint>Type-level representation returned by
NullishOr
.
Creates a union schema of S | null | undefined.
NullishOr<function (type parameter) S in <S extends Constraint>(self: S): NullishOr<S>S>
readonly "~lambda.out": this["~lambda.in"] extends Constraint ? interface NullishOr<S extends Constraint>Type-level representation returned by
NullishOr
.
Creates a union schema of S | null | undefined.
NullishOr<this["~lambda.in"]> : never
}
/**
* Creates a union schema of `S | null | undefined`.
*
* @category constructors
* @since 3.10.0
*/
export const const NullishOr: NullishOrLambdaType-level representation returned by
NullishOr
.
Creates a union schema of S | null | undefined.
NullishOr = import Struct_Struct_.const lambda: <NullishOrLambda>(
f: (a: Constraint) => NullishOr<Constraint>
) => NullishOrLambda
Wraps a plain function as a
Lambda
value so it can be used with
When to use
Use to create a typed lambda for struct mapping APIs that need type-level
input and output tracking.
Details
The type parameter L encodes both the input and output types at the type
level, allowing the compiler to track how struct value types change. At
runtime, the returned value is the same function; lambda only adjusts the
type.
Example (Wrapping values in arrays)
import { pipe, Struct } from "effect"
interface AsArray extends Struct.Lambda {
<A>(self: A): Array<A>
readonly "~lambda.out": Array<this["~lambda.in"]>
}
const asArray = Struct.lambda<AsArray>((a) => [a])
const result = pipe({ x: 1, y: "hello" }, Struct.map(asArray))
console.log(result) // { x: [1], y: ["hello"] }
lambda<NullishOrLambda>((self: Constraint(parameter) self: {
ast: SchemaAST.AST;
Type: unknown;
Encoded: unknown;
DecodingServices: unknown;
EncodingServices: unknown;
Iso: unknown;
}
self) => function Union<
Members extends ReadonlyArray<Constraint>
>(
members: Members,
options?: { mode?: "anyOf" | "oneOf" }
): Union<Members>
Creates a union schema from an array of member schemas. Members are tested in
order; the first match is returned.
Details
Optionally, specify mode:
"anyOf" (default) — matches if any member matches.
"oneOf" — matches if exactly one member matches.
Example (Defining a string or number union)
import { Schema } from "effect"
const schema = Schema.Union([Schema.String, Schema.Number])
Schema.decodeUnknownSync(schema)("hello") // "hello"
Schema.decodeUnknownSync(schema)(42) // 42
Union([self: Constraint(parameter) self: {
ast: SchemaAST.AST;
Type: unknown;
Encoded: unknown;
DecodingServices: unknown;
EncodingServices: unknown;
Iso: unknown;
}
self, const Null: Nullconst Null: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<null, readonly []>) => Null;
annotateKey: (annotations: Annotations.Key<null>) => Null;
check: (checks_0: SchemaAST.Check<null>, ...checks: Array<SchemaAST.Check<null>>) => Null;
rebuild: (ast: SchemaAST.Null) => Null;
make: (input: null, options?: MakeOptions) => null;
makeOption: (input: null, options?: MakeOptions) => Option_.Option<null>;
makeEffect: (input: null, options?: MakeOptions) => Effect.Effect<null, 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; <…;
}
Type-level representation of
Null
.
Schema for the null literal. Validates that the input is strictly null.
Null, const Undefined: Undefinedconst Undefined: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<undefined, readonly []>) => Undefined;
annotateKey: (annotations: Annotations.Key<undefined>) => Undefined;
check: (checks_0: SchemaAST.Check<undefined>, ...checks: Array<SchemaAST.Check<undefined>>) => Undefined;
rebuild: (ast: SchemaAST.Undefined) => Undefined;
make: (input: undefined, options?: MakeOptions) => undefined;
makeOption: (input: undefined, options?: MakeOptions) => Option_.Option<undefined>;
makeEffect: (input: undefined, options?: MakeOptions) => Effect.Effect<undefined, 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; <…;
}
Type-level representation of
Undefined
.
Schema for the undefined literal. Validates that the input is strictly undefined.
Undefined]))