If i got it correct, we create do declare module "xyz" { for the repo's not having interface?
I was going through this code in the repo where the author have created multiple interface inside declare module
declare module "express-rate-limit" {
import { Request, Response, NextFunction } from "express";
interface RateLimitReturnType {
(req: Request, res: Response, next: NextFunction): void;
}
interface Options {
max?: number;
message?: any;
headers?: boolean;
windowMs?: number;
store?: Store | any;
statusCode?: number;
skipFailedRequests?: boolean;
skipSuccessfulRequests?: boolean;
skip?(req?: Request, res?: Response): boolean;
onLimitReached?(req?: Request, res?: Response): void;
handler?(req: Request, res: Response, next?: NextFunction): void;
keyGenerator?(req: Request, res?: Response): string | Request["ip"];
}
interface Store {
hits: {
[key: string]: number;
};
resetAll(): void;
resetTime: number;
setInterval: NodeJS.Timeout;
resetKey(key: string | any): void;
decrement(key: string | any): void;
incr(key: string | any, cb: (err?: Error, hits?: number) => void): void;
}
export default function check(options?: Options): RateLimitReturnType;
}
And then this is how he is using it
const rateLimiter = RateLimit({
windowMs: RATE_LIMIT_TIME,
max: RATE_LIMIT_MAX
});
const publicRateLimiter = RateLimit({
windowMs: PUBLIC_RATE_LIMIT_TIME,
max: PUBLIC_RATE_LIMIT_MAX
});
const speedLimiter = slowDown({
windowMs: SPEED_LIMIT_TIME,
delayAfter: SPEED_LIMIT_COUNT,
delayMs: SPEED_LIMIT_DELAY
});
So I have three questions based on this..
- Why do we create multiple interface inside a declare module?
- How does typescript knows which interface should the type match with?
and can someone explain me these lines
1.
export default function check(options?: Options): RateLimitReturnType;
interface RateLimitReturnType { (req: Request, res: Response, next: NextFunction): void; }


