title: What is the Record type in typescript?
body: <p>What does <code>Record&lt;K, T&gt;</code> mean in Typescript?</p>
  <p>Typescript 2.1 introduced the <code>Record</code> type, describing it in an example:</p>
  <blockquote>
  <pre><code>// For every properties K of type T, transform it to U
  function mapObject&lt;K extends string, T, U&gt;(obj: Record&lt;K, T&gt;, f: (x: T) =&gt; U): Record&lt;K, U&gt;
  </code></pre>
  </blockquote>
  <p>see <a href="https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html#partial-readonly-record-and-pick" rel="noreferrer">Typescript 2.1</a></p>
  <p>And the <a href="https://www.typescriptlang.org/docs/handbook/advanced-types.html" rel="noreferrer">Advanced Types</a> page mentions <code>Record</code> under the Mapped Types heading alongside <code>Readonly</code>, <code>Partial</code>, and <code>Pick</code>, in what appears to be its definition:</p>
  <blockquote>
  <pre><code>type Record&lt;K extends string, T&gt; = {
      [P in K]: T;
  }
  </code></pre>
  </blockquote>
  <blockquote>
  <p>Readonly, Partial and Pick are homomorphic whereas Record is not. One clue that Record is not homomorphic is that it doesn’t take an input type to copy properties from:</p>
  <pre><code>type ThreeStringProps = Record&lt;'prop1' | 'prop2' | 'prop3', string&gt;
  </code></pre>
  </blockquote>
  <p>And that's it. Besides the above quotes, there is no other mention of <code>Record</code> on <a href="https://www.google.com/search?q=site:https://www.typescriptlang.org/+record&amp;filter=0&amp;biw=1372&amp;bih=835" rel="noreferrer">typescriptlang.org</a>.</p>
  <h2>Questions</h2>
  <ol>
  <li><p>Can someone give a simple definition of what <code>Record</code> is?</p>
  </li>
  <li><p>Is <code>Record&lt;K,T&gt;</code> merely a way of saying &quot;all properties on this object will have type <code>T</code>&quot;? Probably not <em>all</em> properties, since <code>K</code> has some purpose...</p>
  </li>
  <li><p>Does the <code>K</code> generic forbid additional keys on the object that are not <code>K</code>, or does it allow them and just indicate that their properties are not transformed to <code>T</code>?</p>
  </li>
  <li><p>With the given example:</p>
  <pre><code>type ThreeStringProps = Record&lt;'prop1' | 'prop2' | 'prop3', string&gt;
  </code></pre>
  <p>Is it exactly the same as this?:</p>
  <pre><code>type ThreeStringProps = {prop1: string, prop2: string, prop3: string}
  </code></pre>
  </li>
  </ol>