Intermediate
A Generic Stack
The Stack class stores unknown, so every value you take out has to be checked. The program already writes new Stack<number>(), which is an error until the class has a type parameter.
Make Stack generic. A Stack<number> must refuse text, and pop() must return number | undefined.
What Check tests
- Your code has no type errors
- The console prints
2 1 - A
Stack<string>accepts text - A
Stack<number>refuses text pop()returnsnumber | undefinedpop()is not a plainnumber
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
Runs in your browser. Your code is saved here.
Press Run to see the page.
Console
Nothing printed yet.