<Entry extends readonly [string | symbol, any]>(
entries: Iterable<Entry>
): Record<ReadonlyRecord.NonLiteralKey<Entry[0]>, Entry[1]>Builds a record from an iterable of key-value pairs.
Details
If there are conflicting keys when using fromEntries, the last occurrence of the key/value pair will overwrite the
previous ones. So the resulting record will only have the value of the last occurrence of each key.
Example (Building a record from entries)
import { Record } from "effect"
import * as assert from "node:assert"
const input: Array<[string, number]> = [["a", 1], ["b", 2]]
assert.deepStrictEqual(Record.fromEntries(input), { a: 1, b: 2 })export const const fromEntries: <
Entry extends readonly [string | symbol, any]
>(
entries: Iterable<Entry>
) => Record<
ReadonlyRecord.NonLiteralKey<Entry[0]>,
Entry[1]
>
Builds a record from an iterable of key-value pairs.
Details
If there are conflicting keys when using fromEntries, the last occurrence of the key/value pair will overwrite the
previous ones. So the resulting record will only have the value of the last occurrence of each key.
Example (Building a record from entries)
import { Record } from "effect"
import * as assert from "node:assert"
const input: Array<[string, number]> = [["a", 1], ["b", 2]]
assert.deepStrictEqual(Record.fromEntries(input), { a: 1, b: 2 })
fromEntries: <function (type parameter) Entry in <Entry extends readonly [string | symbol, any]>(entries: Iterable<Entry>): Record<ReadonlyRecord.NonLiteralKey<Entry[0]>, Entry[1]>Entry extends readonly [string | symbol, any]>(
entries: Iterable<Entry>entries: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) Entry in <Entry extends readonly [string | symbol, any]>(entries: Iterable<Entry>): Record<ReadonlyRecord.NonLiteralKey<Entry[0]>, Entry[1]>Entry>
) => type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<ReadonlyRecord.type ReadonlyRecord<in out K extends string | symbol, out A>.NonLiteralKey<K extends string | symbol> = K extends string ? ReadonlyRecord.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) Entry in <Entry extends readonly [string | symbol, any]>(entries: Iterable<Entry>): Record<ReadonlyRecord.NonLiteralKey<Entry[0]>, Entry[1]>Entry[0]>, function (type parameter) Entry in <Entry extends readonly [string | symbol, any]>(entries: Iterable<Entry>): Record<ReadonlyRecord.NonLiteralKey<Entry[0]>, Entry[1]>Entry[1]> = var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.fromEntries<T = any>(entries: Iterable<readonly [PropertyKey, T]>): {
[k: string]: T;
} (+1 overload)
Returns an object created by key-value entries for properties and methods
fromEntries