diff --git a/types/rate-limit-redis/index.d.ts b/types/rate-limit-redis/index.d.ts index 4b27c7edff..255fc582ad 100644 --- a/types/rate-limit-redis/index.d.ts +++ b/types/rate-limit-redis/index.d.ts @@ -8,18 +8,27 @@ import { RedisClient } from 'redis'; import IORedis = require('ioredis'); -import { Store } from 'express-rate-limit'; +import { Store, StoreIncrementCallback } from 'express-rate-limit'; -interface RedisStoreOptions { - expiry?: number; - prefix?: string; - resetExpiryOnChange?: boolean; - client?: RedisClient | IORedis.Redis; - redisURL?: string; +declare namespace RedisStore { + interface Options { + expiry?: number; + prefix?: string; + resetExpiryOnChange?: boolean; + client?: RedisClient | IORedis.Redis; + redisURL?: string; + } } -declare var RedisStore: { - new (options?: RedisStoreOptions): Store; -}; +declare class RedisStore implements Store { + constructor(options?: RedisStore.Options); + incr(key: string, cb: StoreIncrementCallback): void; + decrement(key: string): void; + resetKey(key: string): void; + // rate-limit-redis 1.7.0 doesn't actually implement resetAll() and + // express-rate-limit 5.1.1 doesn't actually call it, but it's required by + // the Store interface so it's included here. + resetAll(): void; +} export = RedisStore; diff --git a/types/rate-limit-redis/rate-limit-redis-tests.ts b/types/rate-limit-redis/rate-limit-redis-tests.ts index 1aa8778c08..7069f73249 100644 --- a/types/rate-limit-redis/rate-limit-redis-tests.ts +++ b/types/rate-limit-redis/rate-limit-redis-tests.ts @@ -1,39 +1,38 @@ import { RedisClient } from 'redis'; import IORedis = require('ioredis'); import RedisStore from 'rate-limit-redis'; -import { Store } from 'express-rate-limit'; -let store: Store; +let store: RedisStore; -// $ExpectType Store +// $ExpectType RedisStore store = new RedisStore(); -// $ExpectType Store +// $ExpectType RedisStore store = new RedisStore({ expiry: 1000, }); -// $ExpectType Store +// $ExpectType RedisStore store = new RedisStore({ prefix: 'types', }); -// $ExpectType Store +// $ExpectType RedisStore store = new RedisStore({ resetExpiryOnChange: false, }); -// $ExpectType Store +// $ExpectType RedisStore store = new RedisStore({ client: new RedisClient({}), }); -// $ExpectType Store +// $ExpectType RedisStore store = new RedisStore({ client: new IORedis({}), }); -// $ExpectType Store +// $ExpectType RedisStore store = new RedisStore({ redisURL: 'redis://localhost:6379', });