<Key extends Record.Key, Value extends Constraint>(
key: Key,
value: Value,
options?: {
readonly keyValueCombiner: {
readonly decode?:
| Combiner.Combiner<readonly [Key["Type"], Value["Type"]]>
| undefined
readonly encode?:
| Combiner.Combiner<readonly [Key["Encoded"], Value["Encoded"]]>
| undefined
}
}
): $Record<Key, Value>Defines a record schema whose dynamic properties are selected by a key schema and decoded with a value schema.
Details
For dynamic keys, the key schema selects matching own properties and the value schema decodes or encodes only those selected properties. Checks on string, number, symbol, and template literal key schemas narrow which properties are selected.
For transformed key schemas, property selection is based on encoded property names before the selected key is decoded.
Example (Defining a string-keyed record of numbers)
import { Schema } from "effect"
const schema = Schema.Record(Schema.String, Schema.Number)
// { readonly [x: string]: number }
type R = typeof schema.Type
const result = Schema.decodeUnknownSync(schema)({ a: 1, b: 2 })
console.log(result)
// { a: 1, b: 2 }export declare namespace Record {
/**
* Constraint 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.
*
* @category utility types
* @since 4.0.0
*/
export interface 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 extends interface Codec<out T, out E = T, out RD = never, out RE = never>Namespace of type-level helpers for
Codec
.
A schema that tracks the decoded type T, the encoded type E, and the
Effect services required during decoding (RD) and encoding (RE).
Details
Use Codec<T, E, RD, RE> when you need to preserve full type information
about a schema — both what it decodes to and what it serializes from/to.
Most concrete schemas produced by this module implement Codec.
For APIs that only need one direction, prefer the narrower views:
Decoder
<T, RD> — decode-only
Encoder
<E, RE> — encode-only
Schema
<T> — type-only (no encoded representation)
Example (Accepting a codec that decodes to number from string)
import { Schema } from "effect"
declare function serialize<T>(codec: Schema.Codec<T, string>): string
serialize(Schema.NumberFromString) // ok — decodes number, encoded as string
Codec<type PropertyKey =
| string
| number
| symbol
PropertyKey, type PropertyKey =
| string
| number
| symbol
PropertyKey, unknown, unknown> {
readonly "~type.make": type PropertyKey =
| string
| number
| symbol
PropertyKey
readonly "Iso": type PropertyKey =
| string
| number
| symbol
PropertyKey
}
/**
* Computes the decoded object type for a record schema from its key and value
* schemas.
*
* **Details**
*
* The key schema supplies the property keys and the value schema supplies each
* property's decoded `Type`. Optional and mutable value schemas affect the
* resulting property optionality and writability.
*
* @category utility types
* @since 3.10.0
*/
export type type Record.Type<Key extends Record.Key, Value extends Constraint> = Value extends {
readonly "~type.optionality": "optional";
} ? Value extends {
readonly "~type.mutability": "mutable";
} ? { [P in Key["Type"]]?: Value["Type"] | undefined; } : { readonly [P in Key["Type"]]?: Value["Type"] | undefined; } : Value extends {
readonly "~type.mutability": "mutable";
} ? { [P in Key["Type"]]: Value["Type"]; } : { readonly [P in Key["Type"]]: Value["Type"]; }
Computes the decoded object type for a record schema from its key and value
schemas.
Details
The key schema supplies the property keys and the value schema supplies each
property's decoded Type. Optional and mutable value schemas affect the
resulting property optionality and writability.
Type<function (type parameter) Key in type Record.Type<Key extends Record.Key, Value extends Constraint>Key extends 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, function (type parameter) Value in type Record.Type<Key extends Record.Key, Value extends Constraint>Value extends Constraint> = function (type parameter) Value in type Record.Type<Key extends Record.Key, Value extends Constraint>Value extends
{ readonly "~type.optionality": "optional" } ?
function (type parameter) Value in type Record.Type<Key extends Record.Key, Value extends Constraint>Value extends { readonly "~type.mutability": "mutable" } ? { [function (type parameter) PP in function (type parameter) Key in type Record.Type<Key extends Record.Key, Value extends Constraint>Key["Type"]]?: function (type parameter) Value in type Record.Type<Key extends Record.Key, Value extends Constraint>Value["Type"] }
: { readonly [function (type parameter) PP in function (type parameter) Key in type Record.Type<Key extends Record.Key, Value extends Constraint>Key["Type"]]?: function (type parameter) Value in type Record.Type<Key extends Record.Key, Value extends Constraint>Value["Type"] }
: function (type parameter) Value in type Record.Type<Key extends Record.Key, Value extends Constraint>Value extends { readonly "~type.mutability": "mutable" } ? { [function (type parameter) PP in function (type parameter) Key in type Record.Type<Key extends Record.Key, Value extends Constraint>Key["Type"]]: function (type parameter) Value in type Record.Type<Key extends Record.Key, Value extends Constraint>Value["Type"] }
: { readonly [function (type parameter) PP in function (type parameter) Key in type Record.Type<Key extends Record.Key, Value extends Constraint>Key["Type"]]: function (type parameter) Value in type Record.Type<Key extends Record.Key, Value extends Constraint>Value["Type"] }
/**
* Computes the iso object type for a record schema from the key schema's `Iso`
* keys and the value schema's `Iso` values.
*
* @category utility types
* @since 4.0.0
*/
export type type Record.Iso<Key extends Record.Key, Value extends Constraint> = Value extends {
readonly "~type.optionality": "optional";
} ? Value extends {
readonly "~type.mutability": "mutable";
} ? { [P in Key["Iso"]]?: Value["Iso"] | undefined; } : { readonly [P in Key["Iso"]]?: Value["Iso"] | undefined; } : Value extends {
readonly "~type.mutability": "mutable";
} ? { [P in Key["Iso"]]: Value["Iso"]; } : { readonly [P in Key["Iso"]]: Value["Iso"]; }
Computes the iso object type for a record schema from the key schema's Iso
keys and the value schema's Iso values.
Iso<function (type parameter) Key in type Record.Iso<Key extends Record.Key, Value extends Constraint>Key extends 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, function (type parameter) Value in type Record.Iso<Key extends Record.Key, Value extends Constraint>Value extends Constraint> = function (type parameter) Value in type Record.Iso<Key extends Record.Key, Value extends Constraint>Value extends
{ readonly "~type.optionality": "optional" } ?
function (type parameter) Value in type Record.Iso<Key extends Record.Key, Value extends Constraint>Value extends { readonly "~type.mutability": "mutable" } ? { [function (type parameter) PP in function (type parameter) Key in type Record.Iso<Key extends Record.Key, Value extends Constraint>Key["Iso"]]?: function (type parameter) Value in type Record.Iso<Key extends Record.Key, Value extends Constraint>Value["Iso"] }
: { readonly [function (type parameter) PP in function (type parameter) Key in type Record.Iso<Key extends Record.Key, Value extends Constraint>Key["Iso"]]?: function (type parameter) Value in type Record.Iso<Key extends Record.Key, Value extends Constraint>Value["Iso"] }
: function (type parameter) Value in type Record.Iso<Key extends Record.Key, Value extends Constraint>Value extends { readonly "~type.mutability": "mutable" } ? { [function (type parameter) PP in function (type parameter) Key in type Record.Iso<Key extends Record.Key, Value extends Constraint>Key["Iso"]]: function (type parameter) Value in type Record.Iso<Key extends Record.Key, Value extends Constraint>Value["Iso"] }
: { readonly [function (type parameter) PP in function (type parameter) Key in type Record.Iso<Key extends Record.Key, Value extends Constraint>Key["Iso"]]: function (type parameter) Value in type Record.Iso<Key extends Record.Key, Value extends Constraint>Value["Iso"] }
/**
* Computes the encoded object type for a record schema from the key and value
* schemas' encoded types.
*
* **Details**
*
* Encoded-side optionality and mutability on the value schema determine whether
* the encoded record properties are optional or writable.
*
* @category utility types
* @since 3.10.0
*/
export type type Record.Encoded<Key extends Record.Key, Value extends Constraint> = Value extends {
readonly "~encoded.optionality": "optional";
} ? Value extends {
readonly "~encoded.mutability": "mutable";
} ? { [P in Key["Encoded"]]?: Value["Encoded"] | undefined; } : { readonly [P in Key["Encoded"]]?: Value["Encoded"] | undefined; } : Value extends {
readonly "~encoded.mutability": "mutable";
} ? { [P in Key["Encoded"]]: Value["Encoded"]; } : { readonly [P in Key["Encoded"]]: Value["Encoded"]; }
Computes the encoded object type for a record schema from the key and value
schemas' encoded types.
Details
Encoded-side optionality and mutability on the value schema determine whether
the encoded record properties are optional or writable.
Encoded<function (type parameter) Key in type Record.Encoded<Key extends Record.Key, Value extends Constraint>Key extends 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, function (type parameter) Value in type Record.Encoded<Key extends Record.Key, Value extends Constraint>Value extends Constraint> = function (type parameter) Value in type Record.Encoded<Key extends Record.Key, Value extends Constraint>Value extends
{ readonly "~encoded.optionality": "optional" } ?
function (type parameter) Value in type Record.Encoded<Key extends Record.Key, Value extends Constraint>Value extends { readonly "~encoded.mutability": "mutable" } ? { [function (type parameter) PP in function (type parameter) Key in type Record.Encoded<Key extends Record.Key, Value extends Constraint>Key["Encoded"]]?: function (type parameter) Value in type Record.Encoded<Key extends Record.Key, Value extends Constraint>Value["Encoded"] }
: { readonly [function (type parameter) PP in function (type parameter) Key in type Record.Encoded<Key extends Record.Key, Value extends Constraint>Key["Encoded"]]?: function (type parameter) Value in type Record.Encoded<Key extends Record.Key, Value extends Constraint>Value["Encoded"] }
: function (type parameter) Value in type Record.Encoded<Key extends Record.Key, Value extends Constraint>Value extends { readonly "~encoded.mutability": "mutable" } ? { [function (type parameter) PP in function (type parameter) Key in type Record.Encoded<Key extends Record.Key, Value extends Constraint>Key["Encoded"]]: function (type parameter) Value in type Record.Encoded<Key extends Record.Key, Value extends Constraint>Value["Encoded"] }
: { readonly [function (type parameter) PP in function (type parameter) Key in type Record.Encoded<Key extends Record.Key, Value extends Constraint>Key["Encoded"]]: function (type parameter) Value in type Record.Encoded<Key extends Record.Key, Value extends Constraint>Value["Encoded"] }
/**
* Union of the decoding service requirements of a record's key schema and value
* schema.
*
* @category utility types
* @since 4.0.0
*/
export type type Record.DecodingServices<Key extends Record.Key, Value extends Constraint> = Key["DecodingServices"] | Value["DecodingServices"]Union of the decoding service requirements of a record's key schema and value
schema.
DecodingServices<function (type parameter) Key in type Record.DecodingServices<Key extends Record.Key, Value extends Constraint>Key extends 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, function (type parameter) Value in type Record.DecodingServices<Key extends Record.Key, Value extends Constraint>Value extends Constraint> =
| function (type parameter) Key in type Record.DecodingServices<Key extends Record.Key, Value extends Constraint>Key["DecodingServices"]
| function (type parameter) Value in type Record.DecodingServices<Key extends Record.Key, Value extends Constraint>Value["DecodingServices"]
/**
* Union of the encoding service requirements of a record's key schema and value
* schema.
*
* @category utility types
* @since 4.0.0
*/
export type type Record.EncodingServices<Key extends Record.Key, Value extends Constraint> = Key["EncodingServices"] | Value["EncodingServices"]Union of the encoding service requirements of a record's key schema and value
schema.
EncodingServices<function (type parameter) Key in type Record.EncodingServices<Key extends Record.Key, Value extends Constraint>Key extends 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, function (type parameter) Value in type Record.EncodingServices<Key extends Record.Key, Value extends Constraint>Value extends Constraint> =
| function (type parameter) Key in type Record.EncodingServices<Key extends Record.Key, Value extends Constraint>Key["EncodingServices"]
| function (type parameter) Value in type Record.EncodingServices<Key extends Record.Key, Value extends Constraint>Value["EncodingServices"]
/**
* Computes the input object type accepted when constructing a record value.
*
* **Details**
*
* Keys use the key schema's `~type.make` type and values use the value schema's
* `~type.make` type. Value optionality and mutability determine whether
* properties are optional or writable.
*
* @category utility types
* @since 4.0.0
*/
export type type Record.MakeIn<Key extends Record.Key, Value extends Constraint> = Value extends {
readonly "~encoded.optionality": "optional";
} ? Value extends {
readonly "~encoded.mutability": "mutable";
} ? { [P in Key["~type.make"]]?: Value["~type.make"] | undefined; } : { readonly [P in Key["~type.make"]]?: Value["~type.make"] | undefined; } : Value extends {
readonly "~encoded.mutability": "mutable";
} ? { [P in Key["~type.make"]]: Value["~type.make"]; } : { readonly [P in Key["~type.make"]]: Value["~type.make"]; }
Computes the input object type accepted when constructing a record value.
Details
Keys use the key schema's ~type.make type and values use the value schema's
~type.make type. Value optionality and mutability determine whether
properties are optional or writable.
MakeIn<function (type parameter) Key in type Record.MakeIn<Key extends Record.Key, Value extends Constraint>Key extends 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, function (type parameter) Value in type Record.MakeIn<Key extends Record.Key, Value extends Constraint>Value extends Constraint> = function (type parameter) Value in type Record.MakeIn<Key extends Record.Key, Value extends Constraint>Value extends
{ readonly "~encoded.optionality": "optional" } ?
function (type parameter) Value in type Record.MakeIn<Key extends Record.Key, Value extends Constraint>Value extends { readonly "~encoded.mutability": "mutable" } ? { [function (type parameter) PP in function (type parameter) Key in type Record.MakeIn<Key extends Record.Key, Value extends Constraint>Key["~type.make"]]?: function (type parameter) Value in type Record.MakeIn<Key extends Record.Key, Value extends Constraint>Value["~type.make"] }
: { readonly [function (type parameter) PP in function (type parameter) Key in type Record.MakeIn<Key extends Record.Key, Value extends Constraint>Key["~type.make"]]?: function (type parameter) Value in type Record.MakeIn<Key extends Record.Key, Value extends Constraint>Value["~type.make"] }
: function (type parameter) Value in type Record.MakeIn<Key extends Record.Key, Value extends Constraint>Value extends { readonly "~encoded.mutability": "mutable" } ? { [function (type parameter) PP in function (type parameter) Key in type Record.MakeIn<Key extends Record.Key, Value extends Constraint>Key["~type.make"]]: function (type parameter) Value in type Record.MakeIn<Key extends Record.Key, Value extends Constraint>Value["~type.make"] }
: { readonly [function (type parameter) PP in function (type parameter) Key in type Record.MakeIn<Key extends Record.Key, Value extends Constraint>Key["~type.make"]]: function (type parameter) Value in type Record.MakeIn<Key extends Record.Key, Value extends Constraint>Value["~type.make"] }
}
/**
* Type-level representation returned by {@link Record}.
*
* @category models
* @since 4.0.0
*/
export interface interface $Record<Key extends Record.Key, Value extends Constraint>Type-level representation returned by
Record
.
$Record<function (type parameter) Key in $Record<Key extends Record.Key, Value extends Constraint>Key extends 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, function (type parameter) Value in $Record<Key extends Record.Key, Value extends Constraint>Value extends Constraint> 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 $Record<Key extends Record.Key, Value extends Constraint>Type-level representation returned by
Record
.
$Record<function (type parameter) Key in $Record<Key extends Record.Key, Value extends Constraint>Key, function (type parameter) Value in $Record<Key extends Record.Key, Value extends Constraint>Value>
>
{
readonly "Type": Record.type Record.Type<Key extends Record.Key, Value extends Constraint> = Value extends {
readonly "~type.optionality": "optional";
} ? Value extends {
readonly "~type.mutability": "mutable";
} ? { [P in Key["Type"]]?: Value["Type"] | undefined; } : { readonly [P in Key["Type"]]?: Value["Type"] | undefined; } : Value extends {
readonly "~type.mutability": "mutable";
} ? { [P in Key["Type"]]: Value["Type"]; } : { readonly [P in Key["Type"]]: Value["Type"]; }
Computes the decoded object type for a record schema from its key and value
schemas.
Details
The key schema supplies the property keys and the value schema supplies each
property's decoded Type. Optional and mutable value schemas affect the
resulting property optionality and writability.
Type<function (type parameter) Key in $Record<Key extends Record.Key, Value extends Constraint>Key, function (type parameter) Value in $Record<Key extends Record.Key, Value extends Constraint>Value>
readonly "Encoded": Record.type Record.Encoded<Key extends Record.Key, Value extends Constraint> = Value extends {
readonly "~encoded.optionality": "optional";
} ? Value extends {
readonly "~encoded.mutability": "mutable";
} ? { [P in Key["Encoded"]]?: Value["Encoded"] | undefined; } : { readonly [P in Key["Encoded"]]?: Value["Encoded"] | undefined; } : Value extends {
readonly "~encoded.mutability": "mutable";
} ? { [P in Key["Encoded"]]: Value["Encoded"]; } : { readonly [P in Key["Encoded"]]: Value["Encoded"]; }
Computes the encoded object type for a record schema from the key and value
schemas' encoded types.
Details
Encoded-side optionality and mutability on the value schema determine whether
the encoded record properties are optional or writable.
Encoded<function (type parameter) Key in $Record<Key extends Record.Key, Value extends Constraint>Key, function (type parameter) Value in $Record<Key extends Record.Key, Value extends Constraint>Value>
readonly "DecodingServices": Record.type Record.DecodingServices<Key extends Record.Key, Value extends Constraint> = Key["DecodingServices"] | Value["DecodingServices"]Union of the decoding service requirements of a record's key schema and value
schema.
DecodingServices<function (type parameter) Key in $Record<Key extends Record.Key, Value extends Constraint>Key, function (type parameter) Value in $Record<Key extends Record.Key, Value extends Constraint>Value>
readonly "EncodingServices": Record.type Record.EncodingServices<Key extends Record.Key, Value extends Constraint> = Key["EncodingServices"] | Value["EncodingServices"]Union of the encoding service requirements of a record's key schema and value
schema.
EncodingServices<function (type parameter) Key in $Record<Key extends Record.Key, Value extends Constraint>Key, function (type parameter) Value in $Record<Key extends Record.Key, Value extends Constraint>Value>
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<Record.type Record.MakeIn<Key extends Record.Key, Value extends Constraint> = Value extends {
readonly "~encoded.optionality": "optional";
} ? Value extends {
readonly "~encoded.mutability": "mutable";
} ? { [P in Key["~type.make"]]?: Value["~type.make"] | undefined; } : { readonly [P in Key["~type.make"]]?: Value["~type.make"] | undefined; } : Value extends {
readonly "~encoded.mutability": "mutable";
} ? { [P in Key["~type.make"]]: Value["~type.make"]; } : { readonly [P in Key["~type.make"]]: Value["~type.make"]; }
Computes the input object type accepted when constructing a record value.
Details
Keys use the key schema's ~type.make type and values use the value schema's
~type.make type. Value optionality and mutability determine whether
properties are optional or writable.
MakeIn<function (type parameter) Key in $Record<Key extends Record.Key, Value extends Constraint>Key, function (type parameter) Value in $Record<Key extends Record.Key, Value extends Constraint>Value>>
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<Record.type Record.MakeIn<Key extends Record.Key, Value extends Constraint> = Value extends {
readonly "~encoded.optionality": "optional";
} ? Value extends {
readonly "~encoded.mutability": "mutable";
} ? { [P in Key["~type.make"]]?: Value["~type.make"] | undefined; } : { readonly [P in Key["~type.make"]]?: Value["~type.make"] | undefined; } : Value extends {
readonly "~encoded.mutability": "mutable";
} ? { [P in Key["~type.make"]]: Value["~type.make"]; } : { readonly [P in Key["~type.make"]]: Value["~type.make"]; }
Computes the input object type accepted when constructing a record value.
Details
Keys use the key schema's ~type.make type and values use the value schema's
~type.make type. Value optionality and mutability determine whether
properties are optional or writable.
MakeIn<function (type parameter) Key in $Record<Key extends Record.Key, Value extends Constraint>Key, function (type parameter) Value in $Record<Key extends Record.Key, Value extends Constraint>Value>>
readonly "Iso": Record.type Record.Iso<Key extends Record.Key, Value extends Constraint> = Value extends {
readonly "~type.optionality": "optional";
} ? Value extends {
readonly "~type.mutability": "mutable";
} ? { [P in Key["Iso"]]?: Value["Iso"] | undefined; } : { readonly [P in Key["Iso"]]?: Value["Iso"] | undefined; } : Value extends {
readonly "~type.mutability": "mutable";
} ? { [P in Key["Iso"]]: Value["Iso"]; } : { readonly [P in Key["Iso"]]: Value["Iso"]; }
Computes the iso object type for a record schema from the key schema's Iso
keys and the value schema's Iso values.
Iso<function (type parameter) Key in $Record<Key extends Record.Key, Value extends Constraint>Key, function (type parameter) Value in $Record<Key extends Record.Key, Value extends Constraint>Value>
readonly $Record<Key extends Record.Key, Value extends Constraint>.key: Key extends Record.Keykey: function (type parameter) Key in $Record<Key extends Record.Key, Value extends Constraint>Key
readonly $Record<Key extends Record.Key, Value extends Constraint>.value: Value extends Constraintvalue: function (type parameter) Value in $Record<Key extends Record.Key, Value extends Constraint>Value
}
/**
* Defines a record schema whose dynamic properties are selected by a key schema
* and decoded with a value schema.
*
* **Details**
*
* For dynamic keys, the key schema selects matching own properties and the
* value schema decodes or encodes only those selected properties. Checks on
* string, number, symbol, and template literal key schemas narrow which
* properties are selected.
*
* For transformed key schemas, property selection is based on encoded property
* names before the selected key is decoded.
*
* **Example** (Defining a string-keyed record of numbers)
*
* ```ts
* import { Schema } from "effect"
*
* const schema = Schema.Record(Schema.String, Schema.Number)
*
* // { readonly [x: string]: number }
* type R = typeof schema.Type
*
* const result = Schema.decodeUnknownSync(schema)({ a: 1, b: 2 })
* console.log(result)
* // { a: 1, b: 2 }
* ```
*
* @category constructors
* @since 3.10.0
*/
export function function Record<
Key extends Record.Key,
Value extends Constraint
>(
key: Key,
value: Value,
options?: {
readonly keyValueCombiner: {
readonly decode?:
| Combiner.Combiner<
readonly [Key["Type"], Value["Type"]]
>
| undefined
readonly encode?:
| Combiner.Combiner<
readonly [
Key["Encoded"],
Value["Encoded"]
]
>
| undefined
}
}
): $Record<Key, Value>
Defines a record schema whose dynamic properties are selected by a key schema
and decoded with a value schema.
Details
For dynamic keys, the key schema selects matching own properties and the
value schema decodes or encodes only those selected properties. Checks on
string, number, symbol, and template literal key schemas narrow which
properties are selected.
For transformed key schemas, property selection is based on encoded property
names before the selected key is decoded.
Example (Defining a string-keyed record of numbers)
import { Schema } from "effect"
const schema = Schema.Record(Schema.String, Schema.Number)
// { readonly [x: string]: number }
type R = typeof schema.Type
const result = Schema.decodeUnknownSync(schema)({ a: 1, b: 2 })
console.log(result)
// { a: 1, b: 2 }
Record<function (type parameter) Key in Record<Key extends Record.Key, Value extends Constraint>(key: Key, value: Value, options?: {
readonly keyValueCombiner: {
readonly decode?: Combiner.Combiner<readonly [Key["Type"], Value["Type"]]> | undefined;
readonly encode?: Combiner.Combiner<readonly [Key["Encoded"], Value["Encoded"]]> | undefined;
};
}): $Record<Key, Value>
Key extends 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, function (type parameter) Value in Record<Key extends Record.Key, Value extends Constraint>(key: Key, value: Value, options?: {
readonly keyValueCombiner: {
readonly decode?: Combiner.Combiner<readonly [Key["Type"], Value["Type"]]> | undefined;
readonly encode?: Combiner.Combiner<readonly [Key["Encoded"], Value["Encoded"]]> | undefined;
};
}): $Record<Key, Value>
Value extends Constraint>(
key: Key extends Record.Keykey: function (type parameter) Key in Record<Key extends Record.Key, Value extends Constraint>(key: Key, value: Value, options?: {
readonly keyValueCombiner: {
readonly decode?: Combiner.Combiner<readonly [Key["Type"], Value["Type"]]> | undefined;
readonly encode?: Combiner.Combiner<readonly [Key["Encoded"], Value["Encoded"]]> | undefined;
};
}): $Record<Key, Value>
Key,
value: Value extends Constraintvalue: function (type parameter) Value in Record<Key extends Record.Key, Value extends Constraint>(key: Key, value: Value, options?: {
readonly keyValueCombiner: {
readonly decode?: Combiner.Combiner<readonly [Key["Type"], Value["Type"]]> | undefined;
readonly encode?: Combiner.Combiner<readonly [Key["Encoded"], Value["Encoded"]]> | undefined;
};
}): $Record<Key, Value>
Value,
options: {
readonly keyValueCombiner: {
readonly decode?:
| Combiner.Combiner<
readonly [Key["Type"], Value["Type"]]
>
| undefined
readonly encode?:
| Combiner.Combiner<
readonly [
Key["Encoded"],
Value["Encoded"]
]
>
| undefined
}
}
options?: {
readonly keyValueCombiner: {
readonly decode?:
| Combiner.Combiner<
readonly [Key["Type"], Value["Type"]]
>
| undefined
readonly encode?:
| Combiner.Combiner<
readonly [
Key["Encoded"],
Value["Encoded"]
]
>
| undefined
}
keyValueCombiner: {
readonly decode?: | Combiner.Combiner<
readonly [Key["Type"], Value["Type"]]
>
| undefined
decode?: import CombinerCombiner.type Combiner.Combiner = /*unresolved*/ anyCombiner<readonly [function (type parameter) Key in Record<Key extends Record.Key, Value extends Constraint>(key: Key, value: Value, options?: {
readonly keyValueCombiner: {
readonly decode?: Combiner.Combiner<readonly [Key["Type"], Value["Type"]]> | undefined;
readonly encode?: Combiner.Combiner<readonly [Key["Encoded"], Value["Encoded"]]> | undefined;
};
}): $Record<Key, Value>
Key["Type"], function (type parameter) Value in Record<Key extends Record.Key, Value extends Constraint>(key: Key, value: Value, options?: {
readonly keyValueCombiner: {
readonly decode?: Combiner.Combiner<readonly [Key["Type"], Value["Type"]]> | undefined;
readonly encode?: Combiner.Combiner<readonly [Key["Encoded"], Value["Encoded"]]> | undefined;
};
}): $Record<Key, Value>
Value["Type"]]> | undefined
readonly encode?: | Combiner.Combiner<
readonly [Key["Encoded"], Value["Encoded"]]
>
| undefined
encode?: import CombinerCombiner.type Combiner.Combiner = /*unresolved*/ anyCombiner<readonly [function (type parameter) Key in Record<Key extends Record.Key, Value extends Constraint>(key: Key, value: Value, options?: {
readonly keyValueCombiner: {
readonly decode?: Combiner.Combiner<readonly [Key["Type"], Value["Type"]]> | undefined;
readonly encode?: Combiner.Combiner<readonly [Key["Encoded"], Value["Encoded"]]> | undefined;
};
}): $Record<Key, Value>
Key["Encoded"], function (type parameter) Value in Record<Key extends Record.Key, Value extends Constraint>(key: Key, value: Value, options?: {
readonly keyValueCombiner: {
readonly decode?: Combiner.Combiner<readonly [Key["Type"], Value["Type"]]> | undefined;
readonly encode?: Combiner.Combiner<readonly [Key["Encoded"], Value["Encoded"]]> | undefined;
};
}): $Record<Key, Value>
Value["Encoded"]]> | undefined
}
}
): interface $Record<Key extends Record.Key, Value extends Constraint>Type-level representation returned by
Record
.
$Record<function (type parameter) Key in Record<Key extends Record.Key, Value extends Constraint>(key: Key, value: Value, options?: {
readonly keyValueCombiner: {
readonly decode?: Combiner.Combiner<readonly [Key["Type"], Value["Type"]]> | undefined;
readonly encode?: Combiner.Combiner<readonly [Key["Encoded"], Value["Encoded"]]> | undefined;
};
}): $Record<Key, Value>
Key, function (type parameter) Value in Record<Key extends Record.Key, Value extends Constraint>(key: Key, value: Value, options?: {
readonly keyValueCombiner: {
readonly decode?: Combiner.Combiner<readonly [Key["Type"], Value["Type"]]> | undefined;
readonly encode?: Combiner.Combiner<readonly [Key["Encoded"], Value["Encoded"]]> | undefined;
};
}): $Record<Key, Value>
Value> {
const const keyValueCombiner:
| SchemaAST.KeyValueCombiner
| undefined
keyValueCombiner = options: {
readonly keyValueCombiner: {
readonly decode?:
| Combiner.Combiner<
readonly [Key["Type"], Value["Type"]]
>
| undefined
readonly encode?:
| Combiner.Combiner<
readonly [
Key["Encoded"],
Value["Encoded"]
]
>
| undefined
}
}
options?.keyValueCombiner: {
readonly decode?:
| Combiner.Combiner<
readonly [Key["Type"], Value["Type"]]
>
| undefined
readonly encode?:
| Combiner.Combiner<
readonly [
Key["Encoded"],
Value["Encoded"]
]
>
| undefined
}
keyValueCombiner?.decode?: | Combiner.Combiner<
readonly [Key["Type"], Value["Type"]]
>
| undefined
decode || options: {
readonly keyValueCombiner: {
readonly decode?:
| Combiner.Combiner<
readonly [Key["Type"], Value["Type"]]
>
| undefined
readonly encode?:
| Combiner.Combiner<
readonly [
Key["Encoded"],
Value["Encoded"]
]
>
| undefined
}
}
options?.keyValueCombiner: {
readonly decode?:
| Combiner.Combiner<
readonly [Key["Type"], Value["Type"]]
>
| undefined
readonly encode?:
| Combiner.Combiner<
readonly [
Key["Encoded"],
Value["Encoded"]
]
>
| undefined
}
keyValueCombiner?.encode?: | Combiner.Combiner<
readonly [Key["Encoded"], Value["Encoded"]]
>
| undefined
encode
? new import SchemaASTSchemaAST.constructor KeyValueCombiner(decode: Combiner.Combiner<readonly [key: PropertyKey, value: any]> | undefined, encode: Combiner.Combiner<readonly [key: PropertyKey, value: any]> | undefined): SchemaAST.KeyValueCombinerRepresents a bidirectional merge strategy for index signature key-value pairs.
Details
Used by
IndexSignature
when the same key appears multiple times
(e.g. from Schema.extend or overlapping records). Provides separate
decode and encode combiners that determine how duplicate entries are
merged.
KeyValueCombiner(options: {
readonly keyValueCombiner: {
readonly decode?:
| Combiner.Combiner<
readonly [Key["Type"], Value["Type"]]
>
| undefined
readonly encode?:
| Combiner.Combiner<
readonly [
Key["Encoded"],
Value["Encoded"]
]
>
| undefined
}
}
options.keyValueCombiner: {
readonly decode?:
| Combiner.Combiner<
readonly [Key["Type"], Value["Type"]]
>
| undefined
readonly encode?:
| Combiner.Combiner<
readonly [
Key["Encoded"],
Value["Encoded"]
]
>
| undefined
}
keyValueCombiner.decode?: | Combiner.Combiner<
readonly [Key["Type"], Value["Type"]]
>
| undefined
decode, options: {
readonly keyValueCombiner: {
readonly decode?:
| Combiner.Combiner<
readonly [Key["Type"], Value["Type"]]
>
| undefined
readonly encode?:
| Combiner.Combiner<
readonly [
Key["Encoded"],
Value["Encoded"]
]
>
| undefined
}
}
options.keyValueCombiner: {
readonly decode?:
| Combiner.Combiner<
readonly [Key["Type"], Value["Type"]]
>
| undefined
readonly encode?:
| Combiner.Combiner<
readonly [
Key["Encoded"],
Value["Encoded"]
]
>
| undefined
}
keyValueCombiner.encode?: | Combiner.Combiner<
readonly [Key["Encoded"], Value["Encoded"]]
>
| undefined
encode)
: var undefinedundefined
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 record(
key: AST,
value: AST,
keyValueCombiner: KeyValueCombiner | undefined
): Objects
record(key: Key extends Record.Keykey.Bottom<unknown, unknown, unknown, unknown, AST, Top, unknown, unknown, any, unknown, Mutability, Optionality, ConstructorDefault, Mutability, Optionality>["ast"]: SchemaAST.ASTast, value: Value extends Constraintvalue.Constraint["ast"]: SchemaAST.ASTast, const keyValueCombiner:
| SchemaAST.KeyValueCombiner
| undefined
keyValueCombiner), { key: Key extends Record.Keykey, value: Value extends Constraintvalue })
}