我正在尝试将这段代码改编为 typescript :https://github.com/kephin/Node_Redis-Caching/blob/master/services/cache.js ,但我无法扩展查询对象。
目前正在用声明合并扩展它,就像我用 express 做的一样,但在这种情况下它不起作用
declare namespace Mongoose {
interface Query {
cache: any;
}
最佳答案
我设法让它像这样工作:
# mongoose.d.ts
type CacheOptions = { key?: string }
declare module 'mongoose' {
interface DocumentQuery<T, DocType> {
cache(options?: CacheOptions): Query<T>
useCache: boolean
hashKey: string
}
}
关于typescript - 我如何使用 typescript 扩展 Mongoose 查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56206990/