Skip to content
Quiz · Generics · lesson 4 of 10

Quiz — T for two calls

Which types does TypeScript infer for a and b?

TypeScript
function last<T>(xs: T[]): T {
    return xs[xs.length - 1];
}

const a = last([1, 2, 3]);
const b = last(["x", "y"]);
console.log(a, b);