Imagine having an object that has the potential to belong to one of two different classes in a given scenario:
const obj: Class1 | Class2 = ...
if ( checkIfClass1(obj) ) {
// obj = <Class1> obj
...
} else {
// obj = <Class2> obj
...
}
Is there a method to automatically convert obj to its appropriate class based on the outcome of checkIfClass1()?