title: Narrowing string to string literal union
body: <p>I want to narrow a string to a string literal union. In other words, I want to check if the string is one of the possible values of my literal union, so that this will work (if the operator <code>couldbe</code> existed).</p>
  
  <pre><code>type lit = "A" | "B" | "C";
  let uni: lit;
  let str = "B";
  if(str couldbe lit){
      uni = str;
  } else {
      doSomething(str);
  }
  </code></pre>
  
  <p><strong>How can I achieve this?</strong></p>
  
  <p>I tried using <code>if (str instanceof lit)</code>, but that doesn't seem to work. Using <code>keyof</code> to iterate over the string union doesn't work either, because the allowed values aren't keys per se.</p>
  
  <p>One way would be to use <code>switch</code> with one case for each possible value, but that could lead to subtle errors if <code>lit</code>s allowed values change.</p>