StructWithRest<S, Records>Extends a struct schema with one or more record (index-signature) schemas, producing a schema whose decoded type intersects the struct and all records.
Gotchas
TypeScript index signatures also apply to fixed keys. StructWithRest does
not reject incompatible fixed fields at the call site; use
StructWithRest.ValidateRecords when you want an explicit type-level
compatibility check.
Example (Defining structs with string-indexed extra keys)
import { Schema } from "effect"
const schema = Schema.StructWithRest(
Schema.Struct({ id: Schema.Number }),
[Schema.Record(Schema.String, Schema.Number)]
)
// { readonly id: number, readonly [x: string]: number }
type T = typeof schema.Typeexport declare namespace StructWithRest {
/**
* Constraint for object-like schemas that can be used as the fixed portion of a
* `StructWithRest` schema.
*
* @category utility types
* @since 4.0.0
*/
export type type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Objects = Constraint & {
readonly ast: SchemaAST.Objects;
}
Constraint for object-like schemas that can be used as the fixed portion of a
StructWithRest schema.
Objects = Constraint & { readonly ast: SchemaAST.Objects(property) ast: {
_tag: 'Objects';
propertySignatures: ReadonlyArray<PropertySignature>;
indexSignatures: ReadonlyArray<IndexSignature>;
encodingChecks: Checks | undefined;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, recurParameter: (ast: AST) => AST, flipMerge: boolean, checks: Checks | undefined, encodingChecks: Checks | undefined) => Objects;
flip: (recur: (ast: AST) => AST) => AST;
recur: (recur: (ast: AST) => AST, recurParameter?: (ast: AST) => AST) => AST;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast: import SchemaASTSchemaAST.class Objectsclass Objects {
_tag: 'Objects';
propertySignatures: ReadonlyArray<PropertySignature>;
indexSignatures: ReadonlyArray<IndexSignature>;
encodingChecks: Checks | undefined;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, recurParameter: (ast: AST) => AST, flipMerge: boolean, checks: Checks | undefined, encodingChecks: Checks | undefined) => Objects;
flip: (recur: (ast: AST) => AST) => AST;
recur: (recur: (ast: AST) => AST, recurParameter?: (ast: AST) => AST) => AST;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
AST node for object-like schemas, including structs and records.
When to use
Use when constructing or inspecting AST nodes for structs or records rather
than array-like schemas.
Details
propertySignatures — named properties with their types (struct fields).
indexSignatures — index signature entries (record patterns), each with
a parameter AST for matching keys and a type AST for values.
An Objects node with no properties and no index signatures performs only a
non-nullish check: it accepts any value except null and undefined,
including primitive values.
Gotchas
Duplicate property names throw at construction time.
Example (Inspecting a struct AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.Struct({ name: Schema.String })
const ast = schema.ast
if (SchemaAST.isObjects(ast)) {
for (const ps of ast.propertySignatures) {
console.log(ps.name, ps.type._tag)
}
// "name" "String"
}
Objects }
/**
* Readonly list of record schemas that provide the additional index signatures
* for a `StructWithRest` schema.
*
* @category utility types
* @since 3.10.0
*/
export type type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Records = readonly $Record<Record.Key, Constraint>[]Readonly list of record schemas that provide the additional index signatures
for a StructWithRest schema.
Records = interface ReadonlyArray<T>ReadonlyArray<interface $Record<Key extends Record.Key, Value extends Constraint>Type-level representation returned by
Record
.
$Record<Record.interface Record.KeyConstraint for schemas that can be used as record keys.
Details
The key schema must decode and encode property keys (string, number, or
symbol) so it can describe object property names.
Key, Constraint>>
type type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.MergeTuple<T extends ReadonlyArray<unknown>> = T extends readonly [infer Head, ...infer Tail] ? Head & MergeTuple<Tail> : {}MergeTuple<function (type parameter) T in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.MergeTuple<T extends ReadonlyArray<unknown>>T extends interface ReadonlyArray<T>ReadonlyArray<unknown>> = function (type parameter) T in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.MergeTuple<T extends ReadonlyArray<unknown>>T extends readonly [infer function (type parameter) HeadHead, ...infer function (type parameter) TailTail] ?
function (type parameter) HeadHead & type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.MergeTuple<T extends ReadonlyArray<unknown>> = T extends readonly [infer Head, ...infer Tail] ? Head & MergeTuple<Tail> : {}MergeTuple<function (type parameter) TailTail>
: {}
type type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Intersect<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Iso" | "Encoded" | "~type.make"> = S[Side] & MergeTuple<{ readonly [K in keyof Records]: Records[K][Side]; }>Intersect<
function (type parameter) S in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Intersect<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Iso" | "Encoded" | "~type.make">S extends type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Objects = Constraint & {
readonly ast: SchemaAST.Objects;
}
Constraint for object-like schemas that can be used as the fixed portion of a
StructWithRest schema.
Objects,
function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Intersect<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Iso" | "Encoded" | "~type.make">Records extends StructWithRest.type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Records = readonly $Record<Record.Key, Constraint>[]Readonly list of record schemas that provide the additional index signatures
for a StructWithRest schema.
Records,
function (type parameter) Side in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Intersect<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Iso" | "Encoded" | "~type.make">Side extends "Type" | "Iso" | "Encoded" | "~type.make"
> =
& function (type parameter) S in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Intersect<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Iso" | "Encoded" | "~type.make">S[function (type parameter) Side in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Intersect<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Iso" | "Encoded" | "~type.make">Side]
& type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.MergeTuple<T extends ReadonlyArray<unknown>> = T extends readonly [infer Head, ...infer Tail] ? Head & MergeTuple<Tail> : {}MergeTuple<{ readonly [function (type parameter) KK in keyof function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Intersect<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Iso" | "Encoded" | "~type.make">Records]: function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Intersect<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Iso" | "Encoded" | "~type.make">Records[function (type parameter) KK][function (type parameter) Side in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Intersect<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Iso" | "Encoded" | "~type.make">Side] }>
/**
* Computes the decoded type for `StructWithRest` by intersecting the base object
* schema's decoded `Type` with the decoded types of all rest record schemas.
*
* @category utility types
* @since 3.10.0
*/
export type type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Type<S extends StructWithRest.Objects, Records extends StructWithRest.Records> = S["Type"] & MergeTuple<{ readonly [K in keyof Records]: Records[K]["Type"]; }>Computes the decoded type for StructWithRest by intersecting the base object
schema's decoded Type with the decoded types of all rest record schemas.
Type<function (type parameter) S in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Type<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S extends type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Objects = Constraint & {
readonly ast: SchemaAST.Objects;
}
Constraint for object-like schemas that can be used as the fixed portion of a
StructWithRest schema.
Objects, function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Type<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records extends StructWithRest.type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Records = readonly $Record<Record.Key, Constraint>[]Readonly list of record schemas that provide the additional index signatures
for a StructWithRest schema.
Records> = type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Intersect<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Iso" | "Encoded" | "~type.make"> = S[Side] & MergeTuple<{ readonly [K in keyof Records]: Records[K][Side]; }>Intersect<function (type parameter) S in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Type<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S, function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Type<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records, "Type">
/**
* Computes the iso type for `StructWithRest` by intersecting the base object
* schema's `Iso` type with the `Iso` types of all rest record schemas.
*
* @category utility types
* @since 4.0.0
*/
export type type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Iso<S extends StructWithRest.Objects, Records extends StructWithRest.Records> = S["Iso"] & MergeTuple<{ readonly [K in keyof Records]: Records[K]["Iso"]; }>Computes the iso type for StructWithRest by intersecting the base object
schema's Iso type with the Iso types of all rest record schemas.
Iso<function (type parameter) S in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Iso<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S extends type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Objects = Constraint & {
readonly ast: SchemaAST.Objects;
}
Constraint for object-like schemas that can be used as the fixed portion of a
StructWithRest schema.
Objects, function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Iso<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records extends StructWithRest.type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Records = readonly $Record<Record.Key, Constraint>[]Readonly list of record schemas that provide the additional index signatures
for a StructWithRest schema.
Records> = type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Intersect<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Iso" | "Encoded" | "~type.make"> = S[Side] & MergeTuple<{ readonly [K in keyof Records]: Records[K][Side]; }>Intersect<function (type parameter) S in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Iso<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S, function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Iso<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records, "Iso">
/**
* Computes the encoded type for `StructWithRest` by intersecting the base object
* schema's encoded type with the encoded types of all rest record schemas.
*
* @category utility types
* @since 3.10.0
*/
export type type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Encoded<S extends StructWithRest.Objects, Records extends StructWithRest.Records> = S["Encoded"] & MergeTuple<{ readonly [K in keyof Records]: Records[K]["Encoded"]; }>Computes the encoded type for StructWithRest by intersecting the base object
schema's encoded type with the encoded types of all rest record schemas.
Encoded<function (type parameter) S in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Encoded<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S extends type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Objects = Constraint & {
readonly ast: SchemaAST.Objects;
}
Constraint for object-like schemas that can be used as the fixed portion of a
StructWithRest schema.
Objects, function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Encoded<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records extends StructWithRest.type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Records = readonly $Record<Record.Key, Constraint>[]Readonly list of record schemas that provide the additional index signatures
for a StructWithRest schema.
Records> = type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Intersect<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Iso" | "Encoded" | "~type.make"> = S[Side] & MergeTuple<{ readonly [K in keyof Records]: Records[K][Side]; }>Intersect<function (type parameter) S in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Encoded<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S, function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Encoded<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records, "Encoded">
/**
* Computes the input type accepted when constructing a `StructWithRest` value by
* intersecting the base object's make input with the make inputs of all rest
* record schemas.
*
* @category utility types
* @since 4.0.0
*/
export type type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.MakeIn<S extends StructWithRest.Objects, Records extends StructWithRest.Records> = S["~type.make"] & MergeTuple<{ readonly [K in keyof Records]: Records[K]["~type.make"]; }>Computes the input type accepted when constructing a StructWithRest value by
intersecting the base object's make input with the make inputs of all rest
record schemas.
MakeIn<function (type parameter) S in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.MakeIn<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S extends type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Objects = Constraint & {
readonly ast: SchemaAST.Objects;
}
Constraint for object-like schemas that can be used as the fixed portion of a
StructWithRest schema.
Objects, function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.MakeIn<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records extends StructWithRest.type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Records = readonly $Record<Record.Key, Constraint>[]Readonly list of record schemas that provide the additional index signatures
for a StructWithRest schema.
Records> = type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Intersect<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Iso" | "Encoded" | "~type.make"> = S[Side] & MergeTuple<{ readonly [K in keyof Records]: Records[K][Side]; }>Intersect<function (type parameter) S in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.MakeIn<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S, function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.MakeIn<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records, "~type.make">
type type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Services<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "DecodingServices" | "EncodingServices"> = S[Side] | { [K in keyof Records]: Records[K][Side]; }[number]Services<
function (type parameter) S in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Services<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "DecodingServices" | "EncodingServices">S extends type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Objects = Constraint & {
readonly ast: SchemaAST.Objects;
}
Constraint for object-like schemas that can be used as the fixed portion of a
StructWithRest schema.
Objects,
function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Services<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "DecodingServices" | "EncodingServices">Records extends StructWithRest.type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Records = readonly $Record<Record.Key, Constraint>[]Readonly list of record schemas that provide the additional index signatures
for a StructWithRest schema.
Records,
function (type parameter) Side in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Services<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "DecodingServices" | "EncodingServices">Side extends "DecodingServices" | "EncodingServices"
> =
| function (type parameter) S in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Services<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "DecodingServices" | "EncodingServices">S[function (type parameter) Side in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Services<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "DecodingServices" | "EncodingServices">Side]
| { [function (type parameter) KK in keyof function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Services<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "DecodingServices" | "EncodingServices">Records]: function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Services<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "DecodingServices" | "EncodingServices">Records[function (type parameter) KK][function (type parameter) Side in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Services<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "DecodingServices" | "EncodingServices">Side] }[number]
/**
* Union of the decoding service requirements of the base object schema and all
* rest record schemas.
*
* @category utility types
* @since 4.0.0
*/
export type type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.DecodingServices<S extends StructWithRest.Objects, Records extends StructWithRest.Records> = S["DecodingServices"] | { [K in keyof Records]: Records[K]["DecodingServices"]; }[number]Union of the decoding service requirements of the base object schema and all
rest record schemas.
DecodingServices<function (type parameter) S in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.DecodingServices<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S extends type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Objects = Constraint & {
readonly ast: SchemaAST.Objects;
}
Constraint for object-like schemas that can be used as the fixed portion of a
StructWithRest schema.
Objects, function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.DecodingServices<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records extends StructWithRest.type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Records = readonly $Record<Record.Key, Constraint>[]Readonly list of record schemas that provide the additional index signatures
for a StructWithRest schema.
Records> = type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Services<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "DecodingServices" | "EncodingServices"> = S[Side] | { [K in keyof Records]: Records[K][Side]; }[number]Services<
function (type parameter) S in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.DecodingServices<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S,
function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.DecodingServices<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records,
"DecodingServices"
>
/**
* Union of the encoding service requirements of the base object schema and all
* rest record schemas.
*
* @category utility types
* @since 4.0.0
*/
export type type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.EncodingServices<S extends StructWithRest.Objects, Records extends StructWithRest.Records> = S["EncodingServices"] | { [K in keyof Records]: Records[K]["EncodingServices"]; }[number]Union of the encoding service requirements of the base object schema and all
rest record schemas.
EncodingServices<function (type parameter) S in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.EncodingServices<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S extends type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Objects = Constraint & {
readonly ast: SchemaAST.Objects;
}
Constraint for object-like schemas that can be used as the fixed portion of a
StructWithRest schema.
Objects, function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.EncodingServices<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records extends StructWithRest.type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Records = readonly $Record<Record.Key, Constraint>[]Readonly list of record schemas that provide the additional index signatures
for a StructWithRest schema.
Records> = type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Services<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "DecodingServices" | "EncodingServices"> = S[Side] | { [K in keyof Records]: Records[K][Side]; }[number]Services<
function (type parameter) S in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.EncodingServices<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S,
function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.EncodingServices<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records,
"EncodingServices"
>
type type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleKeys<A, B, OK extends (keyof A & keyof B) = Extract<keyof A, keyof B>> = { [K in OK]: Required<Pick<A, K>>[K] extends B[K] ? never : K; }[OK]IncompatibleKeys<function (type parameter) A in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleKeys<A, B, OK extends (keyof A & keyof B) = Extract<keyof A, keyof B>>A, function (type parameter) B in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleKeys<A, B, OK extends (keyof A & keyof B) = Extract<keyof A, keyof B>>B, function (type parameter) OK in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleKeys<A, B, OK extends (keyof A & keyof B) = Extract<keyof A, keyof B>>OK extends (keyof function (type parameter) A in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleKeys<A, B, OK extends (keyof A & keyof B) = Extract<keyof A, keyof B>>A & keyof function (type parameter) B in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleKeys<A, B, OK extends (keyof A & keyof B) = Extract<keyof A, keyof B>>B) = type Extract<T, U> = T extends U
? T
: never
Extract from T those types that are assignable to U
Extract<keyof function (type parameter) A in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleKeys<A, B, OK extends (keyof A & keyof B) = Extract<keyof A, keyof B>>A, keyof function (type parameter) B in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleKeys<A, B, OK extends (keyof A & keyof B) = Extract<keyof A, keyof B>>B>> = {
[function (type parameter) KK in function (type parameter) OK in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleKeys<A, B, OK extends (keyof A & keyof B) = Extract<keyof A, keyof B>>OK]: type Required<T> = {
[P in keyof T]-?: T[P]
}
Make all properties in T required
Required<type Pick<T, K extends keyof T> = {
[P in K]: T[P]
}
From T, pick a set of properties whose keys are in the union K
Pick<function (type parameter) A in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleKeys<A, B, OK extends (keyof A & keyof B) = Extract<keyof A, keyof B>>A, function (type parameter) KK>>[function (type parameter) KK] extends function (type parameter) B in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleKeys<A, B, OK extends (keyof A & keyof B) = Extract<keyof A, keyof B>>B[function (type parameter) KK] ? never : function (type parameter) KK
}[function (type parameter) OK in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleKeys<A, B, OK extends (keyof A & keyof B) = Extract<keyof A, keyof B>>OK]
type type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleSideKeys<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Encoded" | "Iso" | "~type.make"> = { [I in keyof Records]: Records[I][Side] extends object ? IncompatibleKeys<S[Side], Records[I][Side], Extract<keyof S[Side], keyof Records[I][Side]>> : never; }[number]IncompatibleSideKeys<
function (type parameter) S in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleSideKeys<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Encoded" | "Iso" | "~type.make">S extends type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Objects = Constraint & {
readonly ast: SchemaAST.Objects;
}
Constraint for object-like schemas that can be used as the fixed portion of a
StructWithRest schema.
Objects,
function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleSideKeys<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Encoded" | "Iso" | "~type.make">Records extends StructWithRest.type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Records = readonly $Record<Record.Key, Constraint>[]Readonly list of record schemas that provide the additional index signatures
for a StructWithRest schema.
Records,
function (type parameter) Side in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleSideKeys<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Encoded" | "Iso" | "~type.make">Side extends "Type" | "Encoded" | "Iso" | "~type.make"
> = {
[function (type parameter) II in keyof function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleSideKeys<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Encoded" | "Iso" | "~type.make">Records]: function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleSideKeys<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Encoded" | "Iso" | "~type.make">Records[function (type parameter) II][function (type parameter) Side in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleSideKeys<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Encoded" | "Iso" | "~type.make">Side] extends object ? type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleKeys<A, B, OK extends (keyof A & keyof B) = Extract<keyof A, keyof B>> = { [K in OK]: Required<Pick<A, K>>[K] extends B[K] ? never : K; }[OK]IncompatibleKeys<function (type parameter) S in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleSideKeys<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Encoded" | "Iso" | "~type.make">S[function (type parameter) Side in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleSideKeys<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Encoded" | "Iso" | "~type.make">Side], function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleSideKeys<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Encoded" | "Iso" | "~type.make">Records[function (type parameter) II][function (type parameter) Side in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleSideKeys<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Encoded" | "Iso" | "~type.make">Side]> : never
}[number]
type type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleRecords<S extends StructWithRest.Objects, Records extends StructWithRest.Records> = IncompatibleSideKeys<S, Records, "Type"> | IncompatibleSideKeys<S, Records, "Encoded"> | IncompatibleSideKeys<S, Records, "Iso"> | IncompatibleSideKeys<S, Records, "~type.make">IncompatibleRecords<function (type parameter) S in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleRecords<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S extends type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Objects = Constraint & {
readonly ast: SchemaAST.Objects;
}
Constraint for object-like schemas that can be used as the fixed portion of a
StructWithRest schema.
Objects, function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleRecords<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records extends StructWithRest.type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Records = readonly $Record<Record.Key, Constraint>[]Readonly list of record schemas that provide the additional index signatures
for a StructWithRest schema.
Records> =
| type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleSideKeys<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Encoded" | "Iso" | "~type.make"> = { [I in keyof Records]: Records[I][Side] extends object ? IncompatibleKeys<S[Side], Records[I][Side], Extract<keyof S[Side], keyof Records[I][Side]>> : never; }[number]IncompatibleSideKeys<function (type parameter) S in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleRecords<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S, function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleRecords<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records, "Type">
| type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleSideKeys<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Encoded" | "Iso" | "~type.make"> = { [I in keyof Records]: Records[I][Side] extends object ? IncompatibleKeys<S[Side], Records[I][Side], Extract<keyof S[Side], keyof Records[I][Side]>> : never; }[number]IncompatibleSideKeys<function (type parameter) S in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleRecords<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S, function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleRecords<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records, "Encoded">
| type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleSideKeys<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Encoded" | "Iso" | "~type.make"> = { [I in keyof Records]: Records[I][Side] extends object ? IncompatibleKeys<S[Side], Records[I][Side], Extract<keyof S[Side], keyof Records[I][Side]>> : never; }[number]IncompatibleSideKeys<function (type parameter) S in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleRecords<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S, function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleRecords<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records, "Iso">
| type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleSideKeys<S extends StructWithRest.Objects, Records extends StructWithRest.Records, Side extends "Type" | "Encoded" | "Iso" | "~type.make"> = { [I in keyof Records]: Records[I][Side] extends object ? IncompatibleKeys<S[Side], Records[I][Side], Extract<keyof S[Side], keyof Records[I][Side]>> : never; }[number]IncompatibleSideKeys<function (type parameter) S in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleRecords<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S, function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleRecords<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records, "~type.make">
/**
* Checks whether fixed fields are compatible with the rest record schemas.
*
* **Details**
*
* Returns `true` when all fixed fields can also satisfy the matching rest
* index signatures. Returns a diagnostic object when TypeScript would make
* the resulting intersection too narrow for one or more fixed keys.
*
* **Example** (Checking record compatibility)
*
* ```ts
* import { Schema } from "effect"
*
* const user = Schema.Struct({ id: Schema.String })
* const stringExtras = [Schema.Record(Schema.String, Schema.String)] as const
*
* type UserCheck = Schema.StructWithRest.ValidateRecords<typeof user, typeof stringExtras>
*
* const userCheck: UserCheck = true
* void userCheck
*
* const counter = Schema.Struct({ count: Schema.NumberFromString })
*
* type CounterCheck = Schema.StructWithRest.ValidateRecords<typeof counter, typeof stringExtras>
* // ^? { "incompatible index signatures": "count" }
*
* const counterCheck = null as unknown as CounterCheck
* void counterCheck
* ```
*
* @category utility types
* @since 4.0.0
*/
export type type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.ValidateRecords<S extends StructWithRest.Objects, Records extends StructWithRest.Records> = [IncompatibleRecords<S, Records>] extends [never] ? true : {
"incompatible index signatures": IncompatibleRecords<S, Records>;
}
Checks whether fixed fields are compatible with the rest record schemas.
Details
Returns true when all fixed fields can also satisfy the matching rest
index signatures. Returns a diagnostic object when TypeScript would make
the resulting intersection too narrow for one or more fixed keys.
Example (Checking record compatibility)
import { Schema } from "effect"
const user = Schema.Struct({ id: Schema.String })
const stringExtras = [Schema.Record(Schema.String, Schema.String)] as const
type UserCheck = Schema.StructWithRest.ValidateRecords<typeof user, typeof stringExtras>
const userCheck: UserCheck = true
void userCheck
const counter = Schema.Struct({ count: Schema.NumberFromString })
type CounterCheck = Schema.StructWithRest.ValidateRecords<typeof counter, typeof stringExtras>
// ^? { "incompatible index signatures": "count" }
const counterCheck = null as unknown as CounterCheck
void counterCheck
ValidateRecords<
function (type parameter) S in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.ValidateRecords<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S extends type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Objects = Constraint & {
readonly ast: SchemaAST.Objects;
}
Constraint for object-like schemas that can be used as the fixed portion of a
StructWithRest schema.
Objects,
function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.ValidateRecords<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records extends StructWithRest.type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Records = readonly $Record<Record.Key, Constraint>[]Readonly list of record schemas that provide the additional index signatures
for a StructWithRest schema.
Records
> = [type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleRecords<S extends StructWithRest.Objects, Records extends StructWithRest.Records> = IncompatibleSideKeys<S, Records, "Type"> | IncompatibleSideKeys<S, Records, "Encoded"> | IncompatibleSideKeys<S, Records, "Iso"> | IncompatibleSideKeys<S, Records, "~type.make">IncompatibleRecords<function (type parameter) S in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.ValidateRecords<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S, function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.ValidateRecords<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records>] extends [never] ? true
: {
"incompatible index signatures": type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.IncompatibleRecords<S extends StructWithRest.Objects, Records extends StructWithRest.Records> = IncompatibleSideKeys<S, Records, "Type"> | IncompatibleSideKeys<S, Records, "Encoded"> | IncompatibleSideKeys<S, Records, "Iso"> | IncompatibleSideKeys<S, Records, "~type.make">IncompatibleRecords<function (type parameter) S in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.ValidateRecords<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S, function (type parameter) Records in type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.ValidateRecords<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records>
}
}
/**
* Type-level representation returned by {@link StructWithRest}.
*
* @category models
* @since 4.0.0
*/
export interface interface StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Extends a struct schema with one or more record (index-signature) schemas,
producing a schema whose decoded type intersects the struct and all records.
Gotchas
TypeScript index signatures also apply to fixed keys. StructWithRest does
not reject incompatible fixed fields at the call site; use
StructWithRest.ValidateRecords when you want an explicit type-level
compatibility check.
Example (Defining structs with string-indexed extra keys)
import { Schema } from "effect"
const schema = Schema.StructWithRest(
Schema.Struct({ id: Schema.Number }),
[Schema.Record(Schema.String, Schema.Number)]
)
// { readonly id: number, readonly [x: string]: number }
type T = typeof schema.Type
Namespace for StructWithRest type utilities.
Details
StructWithRest.Type<S, R> — decoded type (struct type intersected with record types)
StructWithRest.Encoded<S, R> — encoded type
Type-level representation returned by
StructWithRest
.
StructWithRest<
function (type parameter) S in StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S extends StructWithRest.type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Objects = Constraint & {
readonly ast: SchemaAST.Objects;
}
Constraint for object-like schemas that can be used as the fixed portion of a
StructWithRest schema.
Objects,
function (type parameter) Records in StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records extends StructWithRest.type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Records = readonly $Record<Record.Key, Constraint>[]Readonly list of record schemas that provide the additional index signatures
for a StructWithRest schema.
Records
> 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.class Objectsclass Objects {
_tag: 'Objects';
propertySignatures: ReadonlyArray<PropertySignature>;
indexSignatures: ReadonlyArray<IndexSignature>;
encodingChecks: Checks | undefined;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, recurParameter: (ast: AST) => AST, flipMerge: boolean, checks: Checks | undefined, encodingChecks: Checks | undefined) => Objects;
flip: (recur: (ast: AST) => AST) => AST;
recur: (recur: (ast: AST) => AST, recurParameter?: (ast: AST) => AST) => AST;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
AST node for object-like schemas, including structs and records.
When to use
Use when constructing or inspecting AST nodes for structs or records rather
than array-like schemas.
Details
propertySignatures — named properties with their types (struct fields).
indexSignatures — index signature entries (record patterns), each with
a parameter AST for matching keys and a type AST for values.
An Objects node with no properties and no index signatures performs only a
non-nullish check: it accepts any value except null and undefined,
including primitive values.
Gotchas
Duplicate property names throw at construction time.
Example (Inspecting a struct AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.Struct({ name: Schema.String })
const ast = schema.ast
if (SchemaAST.isObjects(ast)) {
for (const ps of ast.propertySignatures) {
console.log(ps.name, ps.type._tag)
}
// "name" "String"
}
Objects,
interface StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Extends a struct schema with one or more record (index-signature) schemas,
producing a schema whose decoded type intersects the struct and all records.
Gotchas
TypeScript index signatures also apply to fixed keys. StructWithRest does
not reject incompatible fixed fields at the call site; use
StructWithRest.ValidateRecords when you want an explicit type-level
compatibility check.
Example (Defining structs with string-indexed extra keys)
import { Schema } from "effect"
const schema = Schema.StructWithRest(
Schema.Struct({ id: Schema.Number }),
[Schema.Record(Schema.String, Schema.Number)]
)
// { readonly id: number, readonly [x: string]: number }
type T = typeof schema.Type
Namespace for StructWithRest type utilities.
Details
StructWithRest.Type<S, R> — decoded type (struct type intersected with record types)
StructWithRest.Encoded<S, R> — encoded type
Type-level representation returned by
StructWithRest
.
StructWithRest<function (type parameter) S in StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S, function (type parameter) Records in StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records>
>
{
readonly "Type": type Simplify<T> = { [K in keyof T]: T[K]; }Flattens intersection types into a single object type for readability.
When to use
Use when hovering over a type shows A & B & C instead of the merged shape.
Details
This helper is purely cosmetic at the type level and has no runtime effect.
It preserves readonly modifiers; use
Mutable
to strip them.
Example (Flattening an intersection)
import type { Struct } from "effect"
type Original = { a: string } & { b: number }
// Without Simplify, the type displays as `{ a: string } & { b: number }`
type Simplified = Struct.Simplify<Original>
// { a: string; b: number }
Simplify<StructWithRest.type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Type<S extends StructWithRest.Objects, Records extends StructWithRest.Records> = S["Type"] & StructWithRest.MergeTuple<{ readonly [K in keyof Records]: Records[K]["Type"]; }>Computes the decoded type for StructWithRest by intersecting the base object
schema's decoded Type with the decoded types of all rest record schemas.
Type<function (type parameter) S in StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S, function (type parameter) Records in StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records>>
readonly "Encoded": type Simplify<T> = { [K in keyof T]: T[K]; }Flattens intersection types into a single object type for readability.
When to use
Use when hovering over a type shows A & B & C instead of the merged shape.
Details
This helper is purely cosmetic at the type level and has no runtime effect.
It preserves readonly modifiers; use
Mutable
to strip them.
Example (Flattening an intersection)
import type { Struct } from "effect"
type Original = { a: string } & { b: number }
// Without Simplify, the type displays as `{ a: string } & { b: number }`
type Simplified = Struct.Simplify<Original>
// { a: string; b: number }
Simplify<StructWithRest.type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Encoded<S extends StructWithRest.Objects, Records extends StructWithRest.Records> = S["Encoded"] & StructWithRest.MergeTuple<{ readonly [K in keyof Records]: Records[K]["Encoded"]; }>Computes the encoded type for StructWithRest by intersecting the base object
schema's encoded type with the encoded types of all rest record schemas.
Encoded<function (type parameter) S in StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S, function (type parameter) Records in StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records>>
readonly "DecodingServices": StructWithRest.type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.DecodingServices<S extends StructWithRest.Objects, Records extends StructWithRest.Records> = S["DecodingServices"] | { [K in keyof Records]: Records[K]["DecodingServices"]; }[number]Union of the decoding service requirements of the base object schema and all
rest record schemas.
DecodingServices<function (type parameter) S in StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S, function (type parameter) Records in StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records>
readonly "EncodingServices": StructWithRest.type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.EncodingServices<S extends StructWithRest.Objects, Records extends StructWithRest.Records> = S["EncodingServices"] | { [K in keyof Records]: Records[K]["EncodingServices"]; }[number]Union of the encoding service requirements of the base object schema and all
rest record schemas.
EncodingServices<function (type parameter) S in StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S, function (type parameter) Records in StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records>
readonly "~type.make.in": type Simplify<T> = { [K in keyof T]: T[K]; }Flattens intersection types into a single object type for readability.
When to use
Use when hovering over a type shows A & B & C instead of the merged shape.
Details
This helper is purely cosmetic at the type level and has no runtime effect.
It preserves readonly modifiers; use
Mutable
to strip them.
Example (Flattening an intersection)
import type { Struct } from "effect"
type Original = { a: string } & { b: number }
// Without Simplify, the type displays as `{ a: string } & { b: number }`
type Simplified = Struct.Simplify<Original>
// { a: string; b: number }
Simplify<StructWithRest.type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.MakeIn<S extends StructWithRest.Objects, Records extends StructWithRest.Records> = S["~type.make"] & StructWithRest.MergeTuple<{ readonly [K in keyof Records]: Records[K]["~type.make"]; }>Computes the input type accepted when constructing a StructWithRest value by
intersecting the base object's make input with the make inputs of all rest
record schemas.
MakeIn<function (type parameter) S in StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S, function (type parameter) Records in StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records>>
readonly "~type.make": type Simplify<T> = { [K in keyof T]: T[K]; }Flattens intersection types into a single object type for readability.
When to use
Use when hovering over a type shows A & B & C instead of the merged shape.
Details
This helper is purely cosmetic at the type level and has no runtime effect.
It preserves readonly modifiers; use
Mutable
to strip them.
Example (Flattening an intersection)
import type { Struct } from "effect"
type Original = { a: string } & { b: number }
// Without Simplify, the type displays as `{ a: string } & { b: number }`
type Simplified = Struct.Simplify<Original>
// { a: string; b: number }
Simplify<StructWithRest.type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.MakeIn<S extends StructWithRest.Objects, Records extends StructWithRest.Records> = S["~type.make"] & StructWithRest.MergeTuple<{ readonly [K in keyof Records]: Records[K]["~type.make"]; }>Computes the input type accepted when constructing a StructWithRest value by
intersecting the base object's make input with the make inputs of all rest
record schemas.
MakeIn<function (type parameter) S in StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S, function (type parameter) Records in StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records>>
readonly "Iso": type Simplify<T> = { [K in keyof T]: T[K]; }Flattens intersection types into a single object type for readability.
When to use
Use when hovering over a type shows A & B & C instead of the merged shape.
Details
This helper is purely cosmetic at the type level and has no runtime effect.
It preserves readonly modifiers; use
Mutable
to strip them.
Example (Flattening an intersection)
import type { Struct } from "effect"
type Original = { a: string } & { b: number }
// Without Simplify, the type displays as `{ a: string } & { b: number }`
type Simplified = Struct.Simplify<Original>
// { a: string; b: number }
Simplify<StructWithRest.type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Iso<S extends StructWithRest.Objects, Records extends StructWithRest.Records> = S["Iso"] & StructWithRest.MergeTuple<{ readonly [K in keyof Records]: Records[K]["Iso"]; }>Computes the iso type for StructWithRest by intersecting the base object
schema's Iso type with the Iso types of all rest record schemas.
Iso<function (type parameter) S in StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S, function (type parameter) Records in StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records>>
readonly StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.schema: S extends StructWithRest.Objectsschema: function (type parameter) S in StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>S
readonly StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.records: Records extends StructWithRest.Recordsrecords: function (type parameter) Records in StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Records
}
/**
* Extends a struct schema with one or more record (index-signature) schemas,
* producing a schema whose decoded type intersects the struct and all records.
*
* **Gotchas**
*
* TypeScript index signatures also apply to fixed keys. `StructWithRest` does
* not reject incompatible fixed fields at the call site; use
* `StructWithRest.ValidateRecords` when you want an explicit type-level
* compatibility check.
*
* **Example** (Defining structs with string-indexed extra keys)
*
* ```ts
* import { Schema } from "effect"
*
* const schema = Schema.StructWithRest(
* Schema.Struct({ id: Schema.Number }),
* [Schema.Record(Schema.String, Schema.Number)]
* )
*
* // { readonly id: number, readonly [x: string]: number }
* type T = typeof schema.Type
* ```
*
* @category constructors
* @since 4.0.0
*/
export function function StructWithRest<
S extends StructWithRest.Objects,
Records extends StructWithRest.Records
>(
schema: S,
records: Records
): StructWithRest<S, Records>
Extends a struct schema with one or more record (index-signature) schemas,
producing a schema whose decoded type intersects the struct and all records.
Gotchas
TypeScript index signatures also apply to fixed keys. StructWithRest does
not reject incompatible fixed fields at the call site; use
StructWithRest.ValidateRecords when you want an explicit type-level
compatibility check.
Example (Defining structs with string-indexed extra keys)
import { Schema } from "effect"
const schema = Schema.StructWithRest(
Schema.Struct({ id: Schema.Number }),
[Schema.Record(Schema.String, Schema.Number)]
)
// { readonly id: number, readonly [x: string]: number }
type T = typeof schema.Type
StructWithRest<
const function (type parameter) S in StructWithRest<const S extends StructWithRest.Objects, const Records extends StructWithRest.Records>(schema: S, records: Records): StructWithRest<S, Records>S extends StructWithRest.type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Objects = Constraint & {
readonly ast: SchemaAST.Objects;
}
Constraint for object-like schemas that can be used as the fixed portion of a
StructWithRest schema.
Objects,
const function (type parameter) Records in StructWithRest<const S extends StructWithRest.Objects, const Records extends StructWithRest.Records>(schema: S, records: Records): StructWithRest<S, Records>Records extends StructWithRest.type StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>.Records = readonly $Record<Record.Key, Constraint>[]Readonly list of record schemas that provide the additional index signatures
for a StructWithRest schema.
Records
>(
schema: const S extends StructWithRest.Objectsschema: function (type parameter) S in StructWithRest<const S extends StructWithRest.Objects, const Records extends StructWithRest.Records>(schema: S, records: Records): StructWithRest<S, Records>S,
records: const Records extends StructWithRest.Recordsrecords: function (type parameter) Records in StructWithRest<const S extends StructWithRest.Objects, const Records extends StructWithRest.Records>(schema: S, records: Records): StructWithRest<S, Records>Records
): interface StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records>Extends a struct schema with one or more record (index-signature) schemas,
producing a schema whose decoded type intersects the struct and all records.
Gotchas
TypeScript index signatures also apply to fixed keys. StructWithRest does
not reject incompatible fixed fields at the call site; use
StructWithRest.ValidateRecords when you want an explicit type-level
compatibility check.
Example (Defining structs with string-indexed extra keys)
import { Schema } from "effect"
const schema = Schema.StructWithRest(
Schema.Struct({ id: Schema.Number }),
[Schema.Record(Schema.String, Schema.Number)]
)
// { readonly id: number, readonly [x: string]: number }
type T = typeof schema.Type
Namespace for StructWithRest type utilities.
Details
StructWithRest.Type<S, R> — decoded type (struct type intersected with record types)
StructWithRest.Encoded<S, R> — encoded type
Type-level representation returned by
StructWithRest
.
StructWithRest<function (type parameter) S in StructWithRest<const S extends StructWithRest.Objects, const Records extends StructWithRest.Records>(schema: S, records: Records): StructWithRest<S, Records>S, function (type parameter) Records in StructWithRest<const S extends StructWithRest.Objects, const Records extends StructWithRest.Records>(schema: S, records: Records): StructWithRest<S, Records>Records> {
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.function structWithRest(
ast: Objects,
records: ReadonlyArray<Objects>
): Objects
structWithRest(schema: const S extends StructWithRest.Objectsschema."ast": SchemaAST.Objectsast, records: const Records extends StructWithRest.Recordsrecords.ReadonlyArray<$Record<Record.Key, Constraint>>.map<SchemaAST.Objects>(callbackfn: (value: $Record<Record.Key, Constraint>, index: number, array: readonly $Record<Record.Key, Constraint>[]) => SchemaAST.Objects, thisArg?: any): SchemaAST.Objects[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map(import SchemaASTSchemaAST.function getAST<
S extends { readonly ast: AST }
>(self: S): S["ast"]
getAST)), { schema: const S extends StructWithRest.Objectsschema, records: const Records extends StructWithRest.Recordsrecords })
}