Skip to content

Conversation

@she11sh0cked
Copy link

See #38

@syffs
Copy link

syffs commented Apr 1, 2020

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
    }
}

@syffs
Copy link

syffs commented Apr 10, 2020

@boblauer anything missing here ?

@TellonUK
Copy link

TellonUK commented Jul 11, 2020

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 ( typescript-eslint/typescript-eslint#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
}

@she11sh0cked
Copy link
Author

Closing in favor of #63

@she11sh0cked
Copy link
Author

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.

@she11sh0cked she11sh0cked reopened this Nov 5, 2020
@she11sh0cked she11sh0cked changed the title ✏️ Add typedef Add TypeScript definition Nov 5, 2020
@syffs syffs mentioned this pull request Dec 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants