I am trying to reset the textbox values. Tried to set the type 'string | number' to the variable but I am getting an error. So how to set two types to a single variable in typescript. Please help to find the solution.
resetFn() {
var values = Object.values(this.selVal);
var elements = document.getElementsByTagName("input");
for (var i = 0; i < elements.length; i++) {
if (elements[i].type == "text") {
elements[i].value = "";
elements[i].value = values[i]; // getting error
}
}}
Error:
elements[i].value = values[i];
Type 'string | number' is not assignable to type 'string'. Type 'number' is not assignable to type 'string'
Demo: https://stackblitz.com/edit/angular-dzxsg4?file=src%2Fapp%2Fapp.component.ts