The readonly array type of key-value entry tuples
An array of readonly key-value entry tuples [key, value]
An object created from the entries with precise typing
// Fixed-length tuple - exact type inferred
const entries1 = [
['name', 'David'],
['age', 25],
['active', true],
] as const;
const obj1 = Obj.fromEntries(entries1);
assert.deepStrictEqual(obj1, {
name: 'David',
age: 25,
active: true,
});
// Dynamic length array - Partial type applied
const dynamicEntries: (readonly ['x' | 'y', number])[] = [
['x', 10],
['y', 20],
];
const obj2 = Obj.fromEntries(dynamicEntries);
assert.deepStrictEqual(obj2, { x: 10, y: 20 });
Creates an object from an array of key-value pairs with precise TypeScript typing. This is a type-safe wrapper around
Object.fromEntriesthat provides better type inference and compile-time guarantees about the resulting object structure.Type Behavior:
Partialis applied to prevent incorrect assumptions about which keys will be present