title: Not understanding why I can't access property in array of objects in TypeScript
body: <p>When I declare an array of objects, where an an object can be two different types, where one type contains the value I want to get to and the other type does not, how can I access the type when it exists?</p>
  <p>That is, I want to iterate through my <code>items</code> array and print out title when it exists, and otherwise, either skip the record or print out something like &quot;title does not exist&quot;.</p>
  <p>Here is the code with the forEach at the bottom.</p>
  <pre><code>    enum TabItemType {
      Dashboard = &quot;DASHBOARD&quot;,
      SolarEnergy = &quot;SOLARENERGY&quot;,
      PowerUsage = &quot;POWERUSAGE&quot;,
      RateTabe = &quot;RATETABLE&quot;,
      Profile = &quot;PROFILE&quot;,
      Info = &quot;INFO&quot;,
      }
  
      type ItemType = {separator: boolean } |  {
      name: TabItemType; title: string; icon: string; selected?: boolean
      }
  
      const items: Array&lt;ItemType&gt; = [
      {
          name: TabItemType.Dashboard,
          title: &quot;Dashboard&quot;,
          icon: &quot;k-i-grid&quot;,
          selected: true,
      },
      {
          name: TabItemType.SolarEnergy,
          title: &quot;Solar Energy&quot;,
          icon: &quot;k-i-calendar&quot;,
          selected: false,
      },
      { name: TabItemType.PowerUsage, title: &quot;Power Usage&quot;, icon: &quot;k-i-calendar&quot; },
      { name: TabItemType.RateTabe, title: &quot;Rate Table&quot;, icon: &quot;k-i-calendar&quot; },
      { name: TabItemType.Profile, title: &quot;Profile&quot;, icon: &quot;k-i-user&quot; },
      { name: TabItemType.Info, title: &quot;Info&quot;, icon: &quot;k-i-information&quot; },
      ];
  
      items.forEach((rec) =&gt; {
          console.log(rec.name);
      })
  </code></pre>
  <p>Now, I get an error saying</p>
  <pre><code>Property 'name' does not exist on type 'ItemType'.
    Property 'name' does not exist on type '{ separator: boolean; }'
  </code></pre>
  <p><a href="https://www.typescriptlang.org/play?#code/AQ0imB2CuC2wBUCGAjAkgF3LBBPADuMAN4BQYYAIkgM4AWKA9kgE4AmwAvMAESUCCAZQASAIQDy-AEqUeAGnIUQgxgBtWAUUjgWAc1xdeg8QBlpGgHIapAcQCa8xUoAKjAO46AqjSS6i3Hm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