Pretty simple – I’m trying to include a utility class in a React application that isn’t a React class component, but I keep getting the error: Class constructor Stack cannot be invoked without 'new'
Here’s the class:
export default class Stack<T> {
private stack: T[] = []
// Push an item onto the stack
push(item: T): void {
this.stack.push(item)
}
// Pop the top item from the stack and return it
pop(): T | undefined {
return this.stack.pop()
}
// Check if the stack is empty
isEmpty(): boolean {
return this.stack.length === 0
}
// Get the current size of the stack
size(): number {
return this.stack.length
}
// Peek at the top item of the stack without removing it
peek(): T | undefined {
return this.stack[this.stack.length - 1]
}
}
Any hints/tips how I can include this via import like a normal class?
Cheers,
ged12345
Tried to compile as per normal and can’t include/instantiate the class. I’m also using typescript, so it may have something to do with my tconfig.json, but hard to tell what exactly without more information/help.
2