【发布时间】:2016-04-06 03:26:21
【问题描述】:
在mongoose.d.ts“DefinitelyTyped”文件中,geoNear 函数有两个重载:
geoNear(point: { type: string; coordinates: number[] }, options: Object, callback?: (err: any, res: T[]) => void): Query<T[]>;
geoNear(point: number[], options: Object, callback?: (err: any, res: T[]) => void): Query<T[]>;
我已将point 定义为
const point = { type: "Point", coordinates: [lng, lat] }
其中lng 和lat 都是numbers,但是当我这样称呼它时:
Location.geoNear(point, {
spherical: true,
maxDistance: theEarth.getRadiansFromDistance(maxDistance),
num: 10
}, (err, results, stats) => {
var locations = []
results.forEach((doc: any) => {
locations.push({
distance: theEarth.getDistanceFromRadians(doc.dis),
name: doc.obj.name,
address: doc.obj.address,
rating: doc.obj.rating,
facilities: doc.obj.facilities,
_id: doc.obj._id
})
})
res.status(200).json(locations)
})
编译器抱怨
Argument of type '{ type: string; coordinates: number[]; }' is not assignable to parameter of type 'number[]'
如何强制tsc 使用第一个重载?
【问题讨论】:
标签: node.js mongoose typescript overloading