<Sch extends Schema.Top>(itemSchema: Sch): Schema.Struct<{
readonly entryId: Schema.optionalKey<Schema.String>
readonly key: Schema.optional<Schema.String>
readonly item: Schema.optionalKey<Sch>
}>Selector for custom-queue routing verbs.
export const const customQueueEntrySelector: <
Sch extends Schema.Top
>(
itemSchema: Sch
) => Schema.Struct<{
readonly entryId: Schema.optionalKey<Schema.String>
readonly key: Schema.optional<Schema.String>
readonly item: Schema.optionalKey<Sch>
}>
Selector for custom-queue routing verbs.
customQueueEntrySelector = <function (type parameter) Sch in <Sch extends Schema.Top>(itemSchema: Sch): Schema.Struct<{
readonly entryId: Schema.optionalKey<Schema.String>;
readonly key: Schema.optional<Schema.String>;
readonly item: Schema.optionalKey<...>;
}>
Sch extends import SchemaSchema.Top>(itemSchema: Sch extends Schema.TopitemSchema: function (type parameter) Sch in <Sch extends Schema.Top>(itemSchema: Sch): Schema.Struct<{
readonly entryId: Schema.optionalKey<Schema.String>;
readonly key: Schema.optional<Schema.String>;
readonly item: Schema.optionalKey<...>;
}>
Sch) =>
import SchemaSchema.function Struct<{
readonly entryId: Schema.optionalKey<Schema.String>;
readonly key: Schema.optional<Schema.String>;
readonly item: Schema.optionalKey<Sch>;
}>(fields: {
readonly entryId: Schema.optionalKey<Schema.String>;
readonly key: Schema.optional<Schema.String>;
readonly item: Schema.optionalKey<Sch>;
}): Schema.Struct<{
readonly entryId: Schema.optionalKey<Schema.String>;
readonly key: Schema.optional<Schema.String>;
readonly item: Schema.optionalKey<Sch>;
}>
Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Example (Defining a basic struct)
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
console.log(alice)
// { name: 'Alice', age: 30 }
Struct({
entryId: Schema.optionalKey<Schema.String>(property) entryId: {
Type: S["Type"];
Encoded: S["Encoded"];
DecodingServices: S["DecodingServices"];
EncodingServices: S["EncodingServices"];
Iso: S["Iso"];
schema: S;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<string, readonly []>) => Schema.optionalKey<Schema.String>;
annotateKey: (annotations: Schema.Annotations.Key<string>) => Schema.optionalKey<Schema.String>;
check: (checks_0: Check<string>, ...checks: Array<Check<string>>) => Schema.optionalKey<Schema.String>;
rebuild: (ast: String) => Schema.optionalKey<Schema.String>;
make: (input: string, options?: Schema.MakeOptions) => string;
makeOption: (input: string, options?: Schema.MakeOptions) => Option.Option<string>;
makeEffect: (input: string, options?: Schema.MakeOptions) => Effect.Effect<string, Schema.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; <…;
}
entryId: import SchemaSchema.const optionalKey: optionalKeyLambda
<Schema.String>(self: Schema.String) => Schema.optionalKey<Schema.String>
Type-level representation returned by
optionalKey
.
Creates an exact optional key schema for struct fields. Unlike optional,
this creates exact optional properties (not | undefined) that can be
completely omitted from the object.
Example (Creating a struct with optional key)
import { Schema } from "effect"
const schema = Schema.Struct({
name: Schema.String,
age: Schema.optionalKey(Schema.Number)
})
// Type: { readonly name: string; readonly age?: number }
type Person = typeof schema["Type"]
optionalKey(import SchemaSchema.const String: Schema.Stringconst String: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<string, readonly []>) => Schema.String;
annotateKey: (annotations: Schema.Annotations.Key<string>) => Schema.String;
check: (checks_0: Check<string>, ...checks: Array<Check<string>>) => Schema.String;
rebuild: (ast: String) => Schema.String;
make: (input: string, options?: Schema.MakeOptions) => string;
makeOption: (input: string, options?: Schema.MakeOptions) => Option.Option<string>;
makeEffect: (input: string, options?: Schema.MakeOptions) => Effect.Effect<string, Schema.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
String
.
Schema for string values. Validates that the input is typeof "string".
String),
key: Schema.optional<Schema.String>(property) key: {
Rebuild: optional<S>;
Type: S["Type"];
Encoded: S["Encoded"];
DecodingServices: S["DecodingServices"];
EncodingServices: S["EncodingServices"];
Iso: S["Iso"];
schema: S;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<string | undefined, readonly []>) => Schema.optional<Schema.String>;
annotateKey: (annotations: Schema.Annotations.Key<string | undefined>) => Schema.optional<Schema.String>;
check: (checks_0: Check<string | undefined>, ...checks: Array<Check<string | undefined>>) => Schema.optional<Schema.String>;
rebuild: (ast: Union<Undefined | String>) => Schema.optional<Schema.String>;
make: (input: string | undefined, options?: Schema.MakeOptions) => string | undefined;
makeOption: (input: string | undefined, options?: Schema.MakeOptions) => Option.Option<string | undefined>;
makeEffect: (input: string | undefined, options?: Schema.MakeOptions) => Effect.Effect<string | undefined, Schema.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; <…;
}
key: import SchemaSchema.const optional: optionalLambda
<Schema.String>(self: Schema.String) => Schema.optional<Schema.String>
Type-level representation returned by
optional
.
Marks a struct field as optional, allowing the key to be absent or
undefined.
Details
The resulting property may be absent or explicitly set to undefined.
Equivalent to optionalKey(UndefinedOr(S)).
Use
optionalKey
instead if you want exact optional semantics (absent
only, not undefined).
Example (Defining an optional field accepting undefined)
import { Schema } from "effect"
const schema = Schema.Struct({
name: Schema.String,
age: Schema.optional(Schema.Number)
})
// { readonly name: string; readonly age?: number | undefined }
type Person = typeof schema.Type
optional(import SchemaSchema.const String: Schema.Stringconst String: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<string, readonly []>) => Schema.String;
annotateKey: (annotations: Schema.Annotations.Key<string>) => Schema.String;
check: (checks_0: Check<string>, ...checks: Array<Check<string>>) => Schema.String;
rebuild: (ast: String) => Schema.String;
make: (input: string, options?: Schema.MakeOptions) => string;
makeOption: (input: string, options?: Schema.MakeOptions) => Option.Option<string>;
makeEffect: (input: string, options?: Schema.MakeOptions) => Effect.Effect<string, Schema.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
String
.
Schema for string values. Validates that the input is typeof "string".
String),
item: Schema.optionalKey<Sch>(property) item: {
Type: S["Type"];
Encoded: S["Encoded"];
DecodingServices: S["DecodingServices"];
EncodingServices: S["EncodingServices"];
Iso: S["Iso"];
schema: S;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<Sch['Type'], Sch['~type.parameters']>) => Schema.optionalKey<Sch>;
annotateKey: (annotations: Schema.Annotations.Key<Sch['Type']>) => Schema.optionalKey<Sch>;
check: (checks_0: Check<Sch['Type']>, ...checks: Array<Check<Sch['Type']>>) => Schema.optionalKey<Sch>;
rebuild: (ast: Sch['ast']) => Schema.optionalKey<Sch>;
make: (input: Sch['~type.make.in'], options?: Schema.MakeOptions) => Sch['Type'];
makeOption: (input: Sch['~type.make.in'], options?: Schema.MakeOptions) => Option.Option<Sch['Type']>;
makeEffect: (input: Sch['~type.make.in'], options?: Schema.MakeOptions) => Effect.Effect<Sch['Type'], Schema.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; <…;
}
item: import SchemaSchema.const optionalKey: optionalKeyLambda
;<Sch>(self: Sch) => Schema.optionalKey<Sch>
Type-level representation returned by
optionalKey
.
Creates an exact optional key schema for struct fields. Unlike optional,
this creates exact optional properties (not | undefined) that can be
completely omitted from the object.
Example (Creating a struct with optional key)
import { Schema } from "effect"
const schema = Schema.Struct({
name: Schema.String,
age: Schema.optionalKey(Schema.Number)
})
// Type: { readonly name: string; readonly age?: number }
type Person = typeof schema["Type"]
optionalKey(itemSchema: Sch extends Schema.TopitemSchema),
});