title: Typescript assuming I am returning any string even when explicitly checking if the return value is included in an array of specific strings
body: <p>Consider this code:</p>
  <pre><code>const shorcutOptions = ['val1', 'val2'];
  
  type ValueType = number | string;
  type ReturnType = number | 'val1' | 'val2';
  
  export function validValue(value: ValueType): ReturnType {
    if (typeof value === 'string') {
      /**
       * If it's a string, check if it is one of the shortcuts.
       * If so, return it as is.
       */
      if (shorcutOptions.includes(value)) return value; // issue here
  
      /**
       * Anything below is just for the sake of making this example
       * and is of no consequence.
       */
      return parseInt(value);
    }
  
    if (typeof value === 'number') return value;
  
    return 500;
  }
  </code></pre>
  <p>My problem is that on the line marked with <code>// issue here</code>, where I'm getting the red squiggly line under <code>return value;</code> with this error in typescript:</p>
  <blockquote>
  <p><code>Type 'string' is not assignable to type 'ReturnType'.ts(2322)</code></p>
  </blockquote>
  <p>I don't understand why it would assume it's just any <code>string</code> because I'm explicitly checking if <code>value</code> is included in the <code>shortcutOptions</code> array, which means it will only return <code>value</code> if it is equal to <code>'val1'</code> or <code>'val2'</code>.</p>
  <p>I can replace the if statement with <code>if (value === 'val1' || value === 'val2')</code> but in my real-world use-case, I have many more options and it seems redundant.</p>
  <p>I can also replace <code>string</code> in <code>type ValueType = ...</code> with <code>'val1' | 'val2</code>, and the error goes away, but I need this function to accept any string as well.</p>