Exploring TypeScript for the first time and grappling with the concept of generics. I'm puzzled as to why this code snippet isn't working:
function identity<T>(arg: T): T {
let num: number = 2;
return num;
}
let output = identity<number>(1);
Encountering the error: Type 'number' is not assignable to type 'T'. Shouldn't specifying the input as a number also infer that the return type should be compatible, since we've defined T as number?