← All Exercises

Generic Stack Class

intermediatetypescript~20min

Background

Generics enable reusable type-safe data structures in TypeScript applications.

Problem

Create a generic Stack class that maintains type safety for any element type using TypeScript generics.

Input

Elements of any type

Output

Type-safe stack operations

Sample tests

Sample 1

Input: push(1), push(2), pop()
Expected: 2

Your solution

Learning objective

Learn TypeScript generics and type-safe data structures