With Javascript, we have the flexibility to push values that we want to variables easily. However, in TypeScript, how can we block (throw an error) this action?
let array: Array<string> = [];
array.push(5);
console.log(array);
Even though my IDE notifies me that 5 is not a string, the code still compiles and displays the array with the value 5. How can I prevent this? I want my program to halt the operation of pushing 5 to the array.