I'm using typeorm
and nestjs
on my project.
I have a project with multiple actions in one service.
let aorB: A | B;
if(checkpoint === 'A') {
//A point
aorB = await this.Arepository.findOne();
}else{
//B point
aorB = await this.Brepository.findOne();
}
const ab = aorB.onlyAColumn; //error
I used the code above, aorB
would not be changed to type A
in A Point.
I want the type to change at each point.
How can I do this?
You can simply use (aorB as A).onlyAColumn. Or probably these answer might help you TypeScript type cast