I am a beginner with typescript and playing with it on their Playground site. I have the following code:
class Queue<T> {
private data = [];
push = (item: T) => this.data.push(item);
pop = (): T => this.data.shift();
}
let button = document.createElement('button');
button.textContent = "Say Hello";
button.onclick = function () {
let q = new Queue<number>();
q.push("asdada");
alert(q.pop(0));
}
document.body.appendChild(button);
As you can see I created a Queue Object to just accept a number. However, I was able to pass string and able to alert it on my browser. I saw the compiled JS version and it doesn't type check my variable. Isn't typescript supposed to avoid these errors? Or am I mistaken?
Thanks!