Module

x/scaffold/src/deps/npm.ts>objectFromEntries

scaffold your next project with style and 💗
Latest
function objectFromEntries
import { objectFromEntries } from "https://dotland.deno.dev/x/scaffold@0.3.0/src/deps/npm.ts";

A strongly-typed version of Object.fromEntries().

This is useful since Object.fromEntries() always returns {[key: string]: T}. This function returns a strongly-typed object from the given array of entries.

Examples

Example 1

import {objectFromEntries} from 'ts-extras';

const stronglyTypedObjectFromEntries = objectFromEntries([
    ['a', 123],
    ['b', 'someString'],
    ['c', true],
]);
//=> {a: number; b: string; c: boolean}

const untypedEntries = Object.fromEntries(entries);
//=> {[key: string]: string}

Type Parameters

Key extends PropertyKey
Entries extends ReadonlyArray<readonly [Key, unknown]>

Returns

[K in Extract<Entries[number], readonly [Key, unknown]>[0]]: Extract<Entries[number], readonly [K, unknown]>[1]