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?
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);
Here the return is not defined!