ReadonlyRecord<K, A>Represents a readonly record with keys of type K and values of type A.
This is the foundational type for immutable key-value mappings in Effect.
Example (Defining a readonly record type)
import type { Record } from "effect"
// Creating a readonly record type
type UserRecord = Record.ReadonlyRecord<"name" | "age", string | number>
const user: UserRecord = {
name: "John",
age: 30
}export type type ReadonlyRecord<in out K extends string | symbol, out A> = { readonly [P in K]: A; }Represents a readonly record with keys of type K and values of type A.
This is the foundational type for immutable key-value mappings in Effect.
Example (Defining a readonly record type)
import type { Record } from "effect"
// Creating a readonly record type
type UserRecord = Record.ReadonlyRecord<"name" | "age", string | number>
const user: UserRecord = {
name: "John",
age: 30
}
Namespace containing utility types for working with readonly records.
These types help with type-level operations on record keys and values.
Example (Using readonly record helper types)
import type { Record } from "effect"
// Using NonLiteralKey to convert literal keys to generic types
type GenericKey = Record.ReadonlyRecord.NonLiteralKey<"foo" | "bar"> // string
// Using IntersectKeys to find common keys between record types
type CommonKeys = Record.ReadonlyRecord.IntersectKeys<"a" | "b", "b" | "c"> // "b"
ReadonlyRecord<in out function (type parameter) K in type ReadonlyRecord<in out K extends string | symbol, out A>K extends string | symbol, out function (type parameter) A in type ReadonlyRecord<in out K extends string | symbol, out A>A> = {
readonly [function (type parameter) PP in function (type parameter) K in type ReadonlyRecord<in out K extends string | symbol, out A>K]: function (type parameter) A in type ReadonlyRecord<in out K extends string | symbol, out A>A
}
/**
* Namespace containing utility types for working with readonly records.
* These types help with type-level operations on record keys and values.
*
* **Example** (Using readonly record helper types)
*
* ```ts
* import type { Record } from "effect"
*
* // Using NonLiteralKey to convert literal keys to generic types
* type GenericKey = Record.ReadonlyRecord.NonLiteralKey<"foo" | "bar"> // string
*
* // Using IntersectKeys to find common keys between record types
* type CommonKeys = Record.ReadonlyRecord.IntersectKeys<"a" | "b", "b" | "c"> // "b"
* ```
*
* @since 2.0.0
*/
export declare namespace ReadonlyRecord {
type type ReadonlyRecord<in out K extends string | symbol, out A>.IsFiniteString<T extends string> = T extends "" ? true : [T] extends [`${infer Head}${infer Rest}`] ? string extends Head ? false : `${number}` extends Head ? false : Rest extends "" ? true : IsFiniteString<Rest> : falseIsFiniteString<function (type parameter) T in type ReadonlyRecord<in out K extends string | symbol, out A>.IsFiniteString<T extends string>T extends string> = function (type parameter) T in type ReadonlyRecord<in out K extends string | symbol, out A>.IsFiniteString<T extends string>T extends "" ? true :
[function (type parameter) T in type ReadonlyRecord<in out K extends string | symbol, out A>.IsFiniteString<T extends string>T] extends [`${infer function (type parameter) HeadHead}${infer function (type parameter) RestRest}`]
? string extends function (type parameter) HeadHead ? false : `${number}` extends function (type parameter) HeadHead ? false : function (type parameter) RestRest extends "" ? true : type ReadonlyRecord<in out K extends string | symbol, out A>.IsFiniteString<T extends string> = T extends "" ? true : [T] extends [`${infer Head}${infer Rest}`] ? string extends Head ? false : `${number}` extends Head ? false : Rest extends "" ? true : IsFiniteString<Rest> : falseIsFiniteString<function (type parameter) RestRest>
: false
/**
* Represents a type that converts literal string keys to generic string type and symbol keys to generic symbol type.
* This is useful for maintaining type safety while allowing flexible key types in record operations.
*
* **Example** (Converting literal keys to non-literal keys)
*
* ```ts
* import type { Record } from "effect"
*
* // For literal string keys, this becomes 'string'
* type Example1 = Record.ReadonlyRecord.NonLiteralKey<"foo" | "bar"> // string
*
* // For symbol keys, this becomes 'symbol'
* type Example2 = Record.ReadonlyRecord.NonLiteralKey<symbol> // symbol
* ```
*
* @category models
* @since 2.0.0
*/
export type type ReadonlyRecord<in out K extends string | symbol, out A>.NonLiteralKey<K extends string | symbol> = K extends string ? IsFiniteString<K> extends true ? string : K : symbolRepresents a type that converts literal string keys to generic string type and symbol keys to generic symbol type.
This is useful for maintaining type safety while allowing flexible key types in record operations.
Example (Converting literal keys to non-literal keys)
import type { Record } from "effect"
// For literal string keys, this becomes 'string'
type Example1 = Record.ReadonlyRecord.NonLiteralKey<"foo" | "bar"> // string
// For symbol keys, this becomes 'symbol'
type Example2 = Record.ReadonlyRecord.NonLiteralKey<symbol> // symbol
NonLiteralKey<function (type parameter) K in type ReadonlyRecord<in out K extends string | symbol, out A>.NonLiteralKey<K extends string | symbol>K extends string | symbol> = function (type parameter) K in type ReadonlyRecord<in out K extends string | symbol, out A>.NonLiteralKey<K extends string | symbol>K extends string ? type ReadonlyRecord<in out K extends string | symbol, out A>.IsFiniteString<T extends string> = T extends "" ? true : [T] extends [`${infer Head}${infer Rest}`] ? string extends Head ? false : `${number}` extends Head ? false : Rest extends "" ? true : IsFiniteString<Rest> : falseIsFiniteString<function (type parameter) K in type ReadonlyRecord<in out K extends string | symbol, out A>.NonLiteralKey<K extends string | symbol>K> extends true ? string : function (type parameter) K in type ReadonlyRecord<in out K extends string | symbol, out A>.NonLiteralKey<K extends string | symbol>K
: symbol
/**
* Represents the intersection of two key types, handling both literal and non-literal string keys.
* This type is used in record operations that need to compute overlapping keys.
*
* **Example** (Intersecting record keys)
*
* ```ts
* import type { Record } from "effect"
*
* // Intersection of literal keys
* type Example1 = Record.ReadonlyRecord.IntersectKeys<"a" | "b", "b" | "c"> // "b"
*
* // Intersection with generic string
* type Example2 = Record.ReadonlyRecord.IntersectKeys<string, "a" | "b"> // string
* ```
*
* @category models
* @since 2.0.0
*/
export type type ReadonlyRecord<in out K extends string | symbol, out A>.IntersectKeys<K1 extends string, K2 extends string> = [string] extends [K1 | K2] ? NonLiteralKey<K1> & NonLiteralKey<K2> : K1 & K2Represents the intersection of two key types, handling both literal and non-literal string keys.
This type is used in record operations that need to compute overlapping keys.
Example (Intersecting record keys)
import type { Record } from "effect"
// Intersection of literal keys
type Example1 = Record.ReadonlyRecord.IntersectKeys<"a" | "b", "b" | "c"> // "b"
// Intersection with generic string
type Example2 = Record.ReadonlyRecord.IntersectKeys<string, "a" | "b"> // string
IntersectKeys<function (type parameter) K1 in type ReadonlyRecord<in out K extends string | symbol, out A>.IntersectKeys<K1 extends string, K2 extends string>K1 extends string, function (type parameter) K2 in type ReadonlyRecord<in out K extends string | symbol, out A>.IntersectKeys<K1 extends string, K2 extends string>K2 extends string> = [string] extends [function (type parameter) K1 in type ReadonlyRecord<in out K extends string | symbol, out A>.IntersectKeys<K1 extends string, K2 extends string>K1 | function (type parameter) K2 in type ReadonlyRecord<in out K extends string | symbol, out A>.IntersectKeys<K1 extends string, K2 extends string>K2] ?
type ReadonlyRecord<in out K extends string | symbol, out A>.NonLiteralKey<K extends string | symbol> = K extends string ? IsFiniteString<K> extends true ? string : K : symbolRepresents a type that converts literal string keys to generic string type and symbol keys to generic symbol type.
This is useful for maintaining type safety while allowing flexible key types in record operations.
Example (Converting literal keys to non-literal keys)
import type { Record } from "effect"
// For literal string keys, this becomes 'string'
type Example1 = Record.ReadonlyRecord.NonLiteralKey<"foo" | "bar"> // string
// For symbol keys, this becomes 'symbol'
type Example2 = Record.ReadonlyRecord.NonLiteralKey<symbol> // symbol
NonLiteralKey<function (type parameter) K1 in type ReadonlyRecord<in out K extends string | symbol, out A>.IntersectKeys<K1 extends string, K2 extends string>K1> & type ReadonlyRecord<in out K extends string | symbol, out A>.NonLiteralKey<K extends string | symbol> = K extends string ? IsFiniteString<K> extends true ? string : K : symbolRepresents a type that converts literal string keys to generic string type and symbol keys to generic symbol type.
This is useful for maintaining type safety while allowing flexible key types in record operations.
Example (Converting literal keys to non-literal keys)
import type { Record } from "effect"
// For literal string keys, this becomes 'string'
type Example1 = Record.ReadonlyRecord.NonLiteralKey<"foo" | "bar"> // string
// For symbol keys, this becomes 'symbol'
type Example2 = Record.ReadonlyRecord.NonLiteralKey<symbol> // symbol
NonLiteralKey<function (type parameter) K2 in type ReadonlyRecord<in out K extends string | symbol, out A>.IntersectKeys<K1 extends string, K2 extends string>K2>
: function (type parameter) K1 in type ReadonlyRecord<in out K extends string | symbol, out A>.IntersectKeys<K1 extends string, K2 extends string>K1 & function (type parameter) K2 in type ReadonlyRecord<in out K extends string | symbol, out A>.IntersectKeys<K1 extends string, K2 extends string>K2
}