Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript declaration #27

Open
lucasltv opened this issue Jan 23, 2021 · 4 comments
Open

Typescript declaration #27

lucasltv opened this issue Jan 23, 2021 · 4 comments

Comments

@lucasltv
Copy link

Is there any effort to develop the @types/rate-limit-mongo module?

@okv
Copy link
Contributor

okv commented Jan 24, 2021

I don't know about anything like that, please let me know if you find something 😃

@lucasltv
Copy link
Author

I would like to make this, but my problem is: time... Soon... I guess.

@gtmsingh
Copy link

gtmsingh commented Jun 6, 2021

@lucasltv
For now, I was able to use it by creating a sample declaration like so:

  1. Create a index.d.ts in @types/rate-limit-mongo directory inside your repository, with the following content
    /* eslint-disable @typescript-eslint/no-explicit-any */
    declare module 'rate-limit-mongo' {
      export interface MongoStoreOptions {
        uri: string;
        collectionName?: string;
        expireTimeMs?: number;
        resetExpireDateOnChange?: boolean;
        errorHandler?: (err: Error) => void;
        createTtlIndex?: boolean;
      }
      declare class MongoStore {
        constructor(options: MongoStoreOptions);
    
        incr: (key: string, callback: (...args: any[]) => void) => void;
    
        decrement: (key: string, callback?: (...args: any[]) => void) => void;
    
        resetKey: (key: string, callback?: (...args: any[]) => void) => void;
    
        resetAll: () => void;
      }
      export default MongoStore;
    }
  2. Add the types directory to your tsconfig.json:
    {
       "compilerOptions": {
          // other options
          "typeRoots": ["./@types", "node_modules/@types"],
       }
    }

Note: You can further add more options to MongoStoreOptions if you are using them. For e.g. I didn't add host because I was using uri.

Hope this helps!

@stevester94
Copy link

stevester94 commented Apr 13, 2024

I used the following so I wouldn't have to muck with tsconfig.json

At the TOP (It's gotta be the top, I spent way too long on this because I had it in the body) of the file where you are importing rate-limit-mongo

/// <reference path="../custom_types/rate-limit-mongo/index.d.ts" />

where custom_types is an arbitrary folder name

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

No branches or pull requests

4 participants