Skip to content
advanced

Generic Classes

Create a generic Stack class with type-safe push and pop operations.

class Stack___ {
  private items: ___ = [];

  push(item: ___): void {
    this.items.push(item);
  }

  pop(): T | undefined {
    return __________...;
  }

  peek(): T | undefined {
    return this.items[this.items.length - 1];
  }

  isEmpty(): boolean {
    return __________...;
  }

  get size(): number {
    return this.items.length;
  }
}
0/5 filled tab moves · Ctrl+↵ submits · Ctrl+Shift+↵ runsstarter code