title: Typescript: how to make boolean work with discriminated union pair of true/false?
body: <p>I have an interface</p>
  
  <pre><code>interface IData {
    importantData: string
  }
  </code></pre>
  
  <p>and I want to add <code>isLoading</code> flag there. If <code>isLoading = false</code>, then the <code>importantData</code> is loaded and for sure has to be there. However, if <code>isLoading = true</code>, then <code>importantData</code> may be, or may be not there.</p>
  
  <pre><code>interface ILoadedData extends IData {
    isLoading: false
  }
  
  interface ILoadingData extends Partial&lt;IData&gt; {
    isLoading: true
  }
  </code></pre>
  
  <p>So, my final type is a union of these:</p>
  
  <pre><code>type IDataWithLoading = ILoadedData | ILoadingData
  </code></pre>
  
  <p>If I try it works great with boolean literals</p>
  
  <pre><code>const a:IDataWithLoading = ({ isLoading: false, importantData: 'secret' })
  const b:IDataWithLoading = ({ isLoading: false }) // the only error, nice
  const c:IDataWithLoading = ({ isLoading: true })
  const d:IDataWithLoading = ({ isLoading: true, importantData: 'secret' })
  </code></pre>
  
  <p>however, at compile time I don't know whether things are loading or not, so:</p>
  
  <pre><code>const random = Math.random() &gt; 0.5
  const e:IDataWithLoading = ({ isLoading: random, importantData: 'secret' }) // doesn't work
  </code></pre>
  
  <p>It complaints that types are incompatible. It kind of makes sense, since I declared cases for <code>true</code> and <code>false</code>, not for <code>boolean</code>. However, I covered every possible case for <code>boolean</code>, so I sense that TypeScript can understand that and I sense I'm doing something wrong.</p>
  
  <p>If I declare <code>boolean</code> explicitly, however,</p>
  
  <pre><code>interface ILoadingData extends Partial&lt;IData&gt; {
    isLoading: boolean
  }
  </code></pre>
  
  <p>it'll match <code>isLoading = false</code> with <code>Partial&lt;IData&gt;</code>, which is not what I want. What should I do?</p>