title: How can I get typed Object.entries() and Object.fromEntries in Typescript?
body: <p>When I use <code>Object.fromEntries(entries)</code> or <code>Object.entires(obj)</code> in typescript for my typed/const <code>entries</code> arrays or <code>objt</code> objects, I am losing the types to <code>any</code> or a broad type.</p>
  <p>I can manually assign generic types (e.g. <code>Record&lt;string, number&gt;</code>) in some cases, but setting types of each pair/key is tedious.</p>
  <p>Here is an example of what I want.</p>
  <h2>Typed Object.fromEntries(entries)</h2>
  <pre><code>const myArrayOfPairs = [[&quot;a&quot;, 5], [&quot;b&quot;, &quot;hello&quot;], [&quot;c&quot;, false]] as const;
  
  // The type of the following is &quot;any&quot;
  const myTypelessObject = Object.fromEntries(myArrayOfPairs);
  
  // I want the type of this one to be: { a: 5; b: &quot;hello&quot;; c: false; }
  const myTypedObject = createTypedObjectFromEntries(myArrayOfPairs); 
  </code></pre>
  <h2>Typed Object.entries(obj)</h2>
  <pre><code>const myOldObject = {
      x: 6,
      y: &quot;apple&quot;,
      z: true
  };
  
  // The type of the following is [string, string | number | boolean][]
  const myEntries = Object.entries(myOldObject);
  
  // I want the type of this one to be more specific.
  // i.e.: ([&quot;x&quot;, number] | [&quot;y&quot;, string] | [&quot;z&quot;, boolean])[]
  const myTypedEntries = getTypedObjectEntries(myOldObject);
  </code></pre>