title: TypeScript Enums correct usage of logical or
body: <p>Let's say I have an two enums <code>Side</code> and <code>SideDecider</code> and in the latter one I have a key <code>side</code> which should be a value of <code>Side</code> so that when I use <code>SideDecider.side</code> I know it is a value of <code>Side</code>.</p>
  
  <pre class="lang-js prettyprint-override"><code>enum Side {
    left,
    right,
  }
  
  enum SideDecider {
    random,
    other,
    side, // = Side.left | Side.right is what I would like to use
  }
  
  // I am looking for a solution resolving something like the following to true
  console.log(Side.left === SideDecider.side || Side.right === SideDecider.side)
  // error: This condition will always return 'false' since the types 'Side.left' and 'SideDecider.side' have no overlap.
  
  </code></pre>
  
  <p>How would I correctly yield such a usage. Am I trying to incorrectly use <code>enums</code>? Thank you for your help in advance.</p>
  
  <p><a href="https://www.typescriptlang.org/play/#src=enum%20Side%20%7B%0D%0A%20%20left%2C%0D%0A%20%20right%2C%0D%0A%7D%0D%0A%0D%0Aenum%20SideDecider%20%7B%0D%0A%20%20random%2C%0D%0A%20%20other%2C%0D%0A%20%20side%2C%20%2F%2F%20%3D%20Side.left%20%7C%20Side.right%20is%20what%20I%20would%20like%20to%20use%0D%0A%7D%0D%0A%0D%0A%2F%2F%20I%20am%20looking%20for%20a%20solution%20resolving%20something%20like%20the%20following%20to%20true%0D%0Aconsole.log(Side.left%20%3D%3D%3D%20SideDecider.side%20%7C%7C%20Side.right%20%3D%3D%3D%20SideDecider.side)" rel="nofollow noreferrer">Check out example at TypeScript Playground</a></p>
  
  <p><strong>EDIT</strong></p>
  
  <p>What I'm actually trying to achieve is the same but using the <code>enums</code> as strings so I can use these as keys for objects, see <a href="https://typescript-play.js.org/#code/KYOwrgtgBAyglgE2FA3gKClANsAZgFygF4oByHA0gGgygCc4BzAC0JNIZf2rQF800oSLETAAIsADGouqlp0AhiAQB7aO0XK1PTCvzNgs9noN0dUAM6jiIpADoKhAD63gdzqygB6L1ACidHQqdABcUADCagAOYPjACFAAbgpYYMAWUAp0yCB6UFGGEHD4cQlwIJkVQtAA7sXMlvgMIIxJKWkJEMAQAEaGFnwCkiogFoRxYwDyPQBWNuiYjmGkFmrA+uWM5h74y6tdGy08-Gg+UACSmdBYKioA1ptQuMGZliqp+HAj9OnviY-7dbMR5YOB3ZD6ZDPLA3OotKD4FRQADaTTSVARdDSAF00MNRu83DdGAAKZHweyOKAAMmprgk0iQdDsViQGIpbh2NLpHIZMhZomxAEoBGdzhlIdlXjUFABPBFIsAWZC8qT81kQpEKSSSdIZcGyjLlBHpfDTGYAfjxI1WOAcKlJEzNs3JogkCDguuZGuFQA" rel="nofollow noreferrer">my second example</a>. <a href="https://stackoverflow.com/questions/25820171/can-i-have-an-enum-reference-a-text-string">Here</a>, someone recommends using a class for string based enums. Is this best practice?</p>
  
  <pre class="lang-js prettyprint-override"><code>enum Side {
    left = 'left',
    right = 'right',
  }
  
  enum SideDecider {
    random = 'random',
    other = 'other',
    side = Side.left | Side.right // Error: Computed values are not permitted in an enum with string valued members
  }
  
  const testObj = {
    left: 'something',
    right: 'something',
  }
  
  // (1) I am looking for a solution resolving something like the following to [true, true]
  console.log([Side.left &amp;&amp; SideDecider.side, Side.right &amp;&amp; SideDecider.side])
  
  // (2) Is there a way to use SideDecider.side to access keys in testObj?
  console.log(testObj[SideDedicer.side])
  </code></pre>