title: typescript converting Object.entries reduced derived string array to literal types
body: <pre class="lang-js prettyprint-override"><code>const program = {
    morgning: ['breakfast', 'mingle'],
    evning: ['mingle', 'eat', 'party']
  } as const
  
  const namespaceEvent = Object.entries(program).reduce(
    (acc, [namespace, events]) =&gt; [...acc, ...events.map(event =&gt; `${namespace}.${event}`)],
    [] as string[]
  ) // can't do 'as const' here;
  
  type Namespace = typeof namespaceEvent[number] // sees the type as 'string' and not &quot;morgning.breakfast&quot; | &quot;morgning.mingle&quot; | &quot;evning.mingle&quot; | &quot;evning.eat&quot; | &quot;evning.party&quot;
  
  const test: Namespace = 'foo.bar' // would like this to error
  
  console.log(namespaceEvent) // [&quot;morgning.breakfast&quot;, &quot;morgning.mingle&quot;, &quot;evning.mingle&quot;, &quot;evning.eat&quot;, &quot;evning.party&quot;] 
  </code></pre>
  <p>How do I make this work and why doesn't it work?</p>