Skip to content
Quiz · Generics · lesson 10 of 10

Quiz — the type from pop

Which type does TypeScript infer for popped?

TypeScript
class Stack<T> {
    private items: T[] = [];
    push(item: T): void {
        this.items.push(item);
    }
    pop(): T | undefined {
        return this.items.pop();
    }
}
const s = new Stack<string>();
s.push("a");
const popped = s.pop();