title: How to safely convert object to Record
body: <p>How do I safely convert a Typescript <code>object</code> to <code>Record&lt;PropertyKey, unknown&gt;</code>? For example, when reading JSON you get an <code>any</code> object which should really be <code>unknown</code> (I assume it isn't for backwards compatibility):</p>
  <pre class="lang-js prettyprint-override"><code>const ob = JSON.parse(&quot;{}&quot;) as unknown;
  </code></pre>
  <p>I can convert the <code>unknown</code> to an <code>object</code> using a type assertion:</p>
  <pre class="lang-js prettyprint-override"><code>if (typeof ob !== &quot;object&quot; || ob === null) {
    throw new Error(&quot;Not an object&quot;);
  }
  // Typescript now infers the type of ob as `object`
  </code></pre>
  <p>But what check do I now do to convince Typescript that it is safe to treat it as <code>Record&lt;PropertyKey, unknown&gt;</code>? Is it possible that there are <code>object</code>s that aren't <code>Record</code>s?</p>
  <p>I'm sure it has to be said, but I am <em>not</em> looking for <code>ob as Record&lt;PropertyKey, unknown&gt;</code>.</p>