【发布时间】:2020-05-28 12:47:10
【问题描述】:
我对事件调用的函数有以下定义。
forceUpdateLiveLocation: Returns Promise<false | true | LiveLocationChangedEvent[]>
const forcedLiveLocation = await client.forceUpdateLiveLocation( message.from );
console.log(forcedLiveLocation[0]);
有效,但这只返回第一个对象
[{
lat: -2.510491,
lng: -44.220796
}]
当我有几个事件时,他会构建这样的对象:
[ {
lat: -2.510491,
lng: -44.220796
},{
lat: -2343434,
lng: -443434343
}];
所以我尝试对对象执行for,但出现错误。
for(var i = 0; i < forcedLiveLocation.length; i++){
console.log(forcedLiveLocation[i].lat.toString());
}
错误:
“boolean |”类型不存在属性“length” LiveLocationChangedEvent[]'。 类型“false”上不存在属性“length”。
【问题讨论】:
-
尝试打印
console.log(forcedLiveLocation);
标签: javascript node.js typescript