Function objectFromEntries

  • Creates an object from an array of key-value pairs, while maintaining strong typing for the object’s keys and values.

    Type Parameters

    • K extends PropertyKey
    • V

    Parameters

    • entries: [K, V][]

      An array of key-value pairs to convert into an object. Each entry is a tuple of [key, value].

    Returns Record<K, V>

    A new object with the provided key-value pairs, typed as Record<K, V>.

    const entries = [['name', 'Alice'], ['age', 30]] as const;
    const person = objectFromEntries(entries); // Type: { name: string, age: number }