title: TypeScript: type inference when using Array.find
body: <p>why the <code>env</code> can't be a <code>enum type</code> contains all items of list, and how?</p>
  <pre><code>const { hostname, pathname } = window.location
  const rootDir = pathname.split('/')[1]
  const list = ['newstage', 'stage', 'qa3', 'qa2', 't1', 'sit', 'dev']
  const env = list.find(el =&gt; rootDir === el)
  </code></pre>
  <p>now <code>env</code> is <code>const env: string</code>, what I want is
  <code>const env: &quot;stage&quot; | &quot;qa3&quot; | &quot;qa2&quot; | &quot;t1&quot; | &quot;sit&quot; | &quot;dev&quot;</code></p>