So, I have type alias T which represents string | number union type
if I try to add two variables with this type, I'll get variable with type T. But if I take these two variables as parameters of a function it will be an error:
type T = string | number;
function add(a: T, b: T): T{
return a + b;
// Error: Operator '+' cannot be applied to types 'T' and 'T'.
}
let a: T = 1;
let b: T = 'foo';
const c = a + b; // But this is ok
Why I can't do that?
Trefers to a generic, not an alias, but the answer handles the same case)