Add typings for rate-limit-redis (#39036)

* Add typings for rate-limit-redis

* Limit rate-limit-redis to TS 2.3 b/c of express-rate-limit requirement

* Bump rate-limit-redis to TS 2.7
This commit is contained in:
Chris 2019-10-14 19:47:14 -04:00 committed by Andrew Branch
parent dc02437227
commit e72d59512c
5 changed files with 78 additions and 0 deletions

19
types/rate-limit-redis/index.d.ts vendored Normal file
View File

@ -0,0 +1,19 @@
// Type definitions for rate-limit-redis 1.6
// Project: https://github.com/wyattjoh/rate-limit-redis#readme
// Definitions by: Chris Suich <https://github.com/csuich2>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.7
import { RedisClient } from 'redis';
import { Store } from 'express-rate-limit';
interface RedisStoreOptions {
expiry?: number;
prefix?: string;
resetExpiryOnChange?: boolean;
client?: RedisClient;
}
declare function RedisStore(options?: RedisStoreOptions): Store;
export = RedisStore;

View File

@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"express-rate-limit": ">=3.4.0"
}
}

View File

@ -0,0 +1,28 @@
import { RedisClient } from 'redis';
import RedisStore from 'rate-limit-redis';
import { Store } from 'express-rate-limit';
let store: Store;
// $ExpectType Store
store = RedisStore();
// $ExpectType Store
store = RedisStore({
expiry: 1000,
});
// $ExpectType Store
store = RedisStore({
prefix: 'types',
});
// $ExpectType Store
store = RedisStore({
resetExpiryOnChange: false,
});
// $ExpectType Store
store = RedisStore({
client: new RedisClient({}),
});

View File

@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true
},
"files": [
"index.d.ts",
"rate-limit-redis-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }