If you need to cast a generic type parameter to a specific type we can cast it to a object and do the casting like below,
void SomeMethod(T t)
{
SomeClas
If there is no relation between the input type T and the target types TypeA or TypeB (using parameter contraints), and we are looking purely at the casting-problem, the answer is simple:
No, there is no better way than the method you are using!!!
I do agree with some other people, if you are doing more operations on that object, you might wanna choose a different design.