Hint
Generic functions preserve the exact type of their argument through the return type. This is why identity<T>(v: T): T is so powerful — callers get back exactly the type they put in, not a wider type.
// Simulate generic type resolution
function identity(value) {
return value;
}
// TypeScript resolves T to the argument type at each call site
const n = identity(42); // T = number
const s = identity('hello'); // T = string
const a = identity([1, 2, 3]); // T = number[]
const o = identity({ x: 1 }); // T = { x: number }
console.log(typeof n);
console.log(typeof s);
console.log(Array.isArray(a));
console.log(typeof o);
console.log(n + 1); // safe — TypeScript knows it's numbernumber string true object 43
Explanation: Each call resolves T to the exact type of the argument. TypeScript does not widen — identity(42) gives T=number, not T=number|string.
Key Insight: Generic functions preserve the exact type of their argument through the return type. This is why identity