title: Typescript Key-Value relation preserving Object.entries type
body: <p>The typing for <code>Object.entries</code> provided by typescript has the return type <code>[string, T][]</code> but I am searching for a generic type <code>Entries&lt;O&gt;</code> to represent the return value of this function that keeps the relationship between the keys and the values.</p>
  
  <p>Eg. when having an object type like</p>
  
  <pre><code>type Obj = {
      a: number,
      b: string,
      c: number
  }
  </code></pre>
  
  <p>I'm looking for a type <code>Entries&lt;O&gt;</code> that results in one of the types below (or something similar) when provided with <code>Obj</code>:</p>
  
  <pre><code>(["a", number] | ["b", string] | ["c", number])[]
  [["a", number], ["b", string], ["c", number]]
  (["a" | "c", number] | ["b", string])[]
  </code></pre>
  
  <hr>
  
  <p>That this isn't correct for all use cases of Object.entries (<a href="https://stackoverflow.com/questions/55012174/why-doesnt-object-keys-return-a-keyof-type-in-typescript">see here</a>) is no problem for my specific case. </p>
  
  <hr>
  
  <p><strong>Tried and failed solution:</strong></p>
  
  <p><code>type Entries&lt;O&gt; = [keyof O, O[keyof O]][]</code> doesn't work for this as it only preserves the possible keys and values but not the relationship between these as <code>Entries&lt;Obj&gt;</code> is <code>["a" | "b" | "c", number | string]</code>.</p>
  
  <pre><code>type Entry&lt;O, K extends keyof O&gt; = [K, O[K]]
  type Entries&lt;O&gt; = Entry&lt;O, keyof O&gt;[]
  </code></pre>
  
  <p>Here the definition of <code>Entry</code> works as expected eg. <code>Entry&lt;Obj, "a"&gt;</code> is <code>["a", number]</code> but the application of it in the second line with <code>keyof O</code> as the second type variable leads again to the same result as the first try.</p>