【发布时间】:2018-07-30 13:28:29
【问题描述】:
出于某种原因,Typescript 在以下 jQuery 循环中将 index 报告为字符串。
$.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);
}
});
Typescript 正在报告
运算符“
换行
if(index <= (this.options.bounds_marker_limit - 1)) this.bounds.extend(position);.
如果我尝试(index as number) 然后它会报告
类型“字符串”不能转换为类型“数字”
我可以做些什么来修复这个错误?
【问题讨论】:
-
“locations”数组包含哪些元素?
标签: jquery typescript types casting