When running a jQuery loop in Typescript, I encountered an issue where the index
was being reported as a string.
$.each(locations, (index, marker) => {
if(this.options && this.options.bounds_marker_limit) {
if(index <= (this.options.bounds_marker_limit - 1)) this.bounds.extend(position);
} else {
this.bounds.extend(position);
}
});
This resulted in Typescript reporting
An error stating: Operator '<=' cannot be applied to types 'string' and 'number'.
This error specifically points to the line
if(index <= (this.options.bounds_marker_limit - 1)) this.bounds.extend(position);
.
After attempting (index as number)
, the new report is
Error: Type 'string' cannot be converted to type 'number'
I am seeking advice on how to resolve this situation. Any suggestions?