Add TypeScript definition
See #38
Just ran into a typescript issue with cachegoose:
item = await SomeModel.findOne({_id: id}).cache(60)
generating:
TS2551: Property 'cache' does not exist on type 'DocumentQuery<...>'. Did you mean 'catch'?
don't we miss the cache declaration on DocumentQuery/Aggregate here ?
Probably something like this:
declare module 'mongoose' {
interface DocumentQuery<T, DocType extends Document, QueryHelpers = {}> {
cache(ttl?: number, customKey?: string): this
}
interface Aggregate<T> {
cache(ttl?: number, customKey?: string): this
}
}
@boblauer anything missing here ?
I couldn't use {} had to use Record<never,never>>, I tried Record<string,never>> but conflicts with mongoose. If your happy with this controversial solution ( https://github.com/typescript-eslint/typescript-eslint/issues/2063 ) I can submit an updated typedef so we don't have to override locally anymore.
declare module 'mongoose' {
interface DocumentQuery<T, DocType extends Document, QueryHelpers = Record<never,never>> {
cache(ttl?: number, customKey?: string): this
}
interface Aggregate<T> {
cache(ttl?: number, customKey?: string): this
}
}
declare module 'cachegoose' {
import { DocumentQuery, Document, Mongoose } from 'mongoose'
function cachegoose(mongoose: Mongoose, cacheOptions?: cachegoose.Types.IOptions): void
namespace cachegoose {
namespace Types {
interface IOptions {
engine?: string
port?: number
host?: string
}
}
function clearCache(customKey: string, cb?: () => void): void
}
export = cachegoose
}
Closing in favor of #63
Actually no, I will reopen. There are still some problems with my typedef, but I think it's better. I will push some more commits later.