Typescript declaration
Is there any effort to develop the @types/rate-limit-mongo module?
I don't know about anything like that, please let me know if you find something 😃
I would like to make this, but my problem is: time... Soon... I guess.
@lucasltv For now, I was able to use it by creating a sample declaration like so:
- Create a
index.d.tsin@types/rate-limit-mongodirectory 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; } - 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!
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