Is there a way to achieve this without using if/else or switch statements by utilizing function return values?
interface test1 {
type: 'test1'
}
interface test2 {
type: 'test2'
}
type unType = test1 | test2;
//I am aware of the property "type"'s value
//Can I use this information to determine the specific type (test1 or test2) in a function's return value?
function whichType<T>(typeValue): T {
return null;
}
const tt1 = whichType<unType>('test1');// expected output: interface test1
const tt2 = whichType<unType>('test2');// expected output: interface test2