title: Return different type by string in Typescript
body: <p>Given we have two different types as below, how can we change the return of function based on a string parameter and not providing the generic type?</p>
  
  <pre><code>interface Type1 { typeName: string; };
  interface Type2 { typeVersion: string; };
  type AllTypes = Type1 | Type2;
  
  function returnTypes(t: string): AllTypes {
    ...
  }
  
  const typeResult = returnTypes('type1');
  console.log(typeResult.typeName);
  </code></pre>
  
  <p>Here the return is not defined!</p>