title: How to create an object type based on keys/values of a const object in TypeScript?
body: <p>I need to define a type based on a config object (<code>anObject</code>), which will be used in my code.</p>
  <p>I wrote something like the following,</p>
  <pre><code>const anObject = {
    foo: [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;],
    bar: [&quot;d&quot;, &quot;e&quot;, &quot;f&quot;],
  } as const;
  
  type aType =
    | { key: &quot;&quot;; value: [] }
    | { key: &quot;foo&quot;; value: (&quot;a&quot; | &quot;b&quot; | &quot;c&quot;)[] }
    | { key: &quot;bar&quot;; value: (&quot;d&quot; | &quot;e&quot; | &quot;f&quot;)[] };
  
  const a: aType = { key: &quot;&quot;, value: [] }; // No error
  const b: aType = { key: &quot;foo&quot;; value: [&quot;a&quot;, &quot;b&quot;] }; // No error
  const c: aType = { key: &quot;bar&quot;; value: [&quot;e&quot;, &quot;f&quot;] }; // No error
  </code></pre>
  <p>How to declare <code>aType</code> dynamically in TypeScript?</p>