Skip to content

Commit 747dd30

Browse files
committedMar 14, 2022
fix: add the missing typing for Redis#call()
1 parent b530a0b commit 747dd30

File tree

5 files changed

+5128
-10305
lines changed

5 files changed

+5128
-10305
lines changed
 

‎bin/generateRedisCommander/template.ts

+31
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,37 @@ export type Result<T, Context extends ClientContext> =
2020
ResultTypes<T, Context>[Context["type"]];
2121

2222
interface RedisCommander<Context extends ClientContext = { type: "default" }> {
23+
/**
24+
* Call arbitrary commands.
25+
*
26+
* `redis.call('set', 'foo', 'bar')` is the same as `redis.set('foo', 'bar')`,
27+
* so the only case you need to use this method is when the command is not
28+
* supported by ioredis.
29+
*
30+
* ```ts
31+
* redis.call('set', 'foo', 'bar');
32+
* redis.call('get', 'foo', (err, value) => {
33+
* // value === 'bar'
34+
* });
35+
* ```
36+
*/
37+
call(command: string, callback?: Callback<unknown>): Result<unknown, Context>;
38+
call(
39+
command: string,
40+
args: (string | Buffer | number)[],
41+
callback?: Callback<unknown>
42+
): Result<unknown, Context>;
43+
call(
44+
...args: [
45+
command: string,
46+
...args: (string | Buffer | number)[],
47+
callback: Callback<unknown>
48+
]
49+
): Result<unknown, Context>;
50+
call(
51+
...args: [command: string, ...args: (string | Buffer | number)[]]
52+
): Result<unknown, Context>;
53+
2354
////
2455
}
2556

‎lib/utils/Commander.ts

-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ commands.forEach(function (commandName) {
117117
);
118118
});
119119

120-
// @ts-expect-error
121120
Commander.prototype.call = generateFunction("call", "utf8");
122121
// @ts-expect-error
123122
Commander.prototype.callBuffer = generateFunction("callBuffer", null);

‎lib/utils/RedisCommander.ts

+1,626-10,301
Large diffs are not rendered by default.

‎package-lock.json

+3,452-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎test-d/commands.test-d.ts

+19
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,25 @@ import Redis from "../built";
33

44
const redis = new Redis();
55

6+
// call
7+
expectType<Promise<unknown>>(redis.call('info'));
8+
expectType<Promise<unknown>>(redis.call('set', 'foo', 'bar'));
9+
expectType<Promise<unknown>>(redis.call('set', ['foo', 'bar']));
10+
expectType<Promise<unknown>>(redis.call('set', ['foo', 'bar'], (err, value) => {
11+
expectType<Error | undefined | null>(err);
12+
expectType<unknown | undefined>(value);
13+
}));
14+
15+
expectType<Promise<unknown>>(redis.call('get', 'foo', (err, value) => {
16+
expectType<Error | undefined | null>(err);
17+
expectType<unknown | undefined>(value);
18+
}));
19+
20+
expectType<Promise<unknown>>(redis.call('info', (err, value) => {
21+
expectType<Error | undefined | null>(err);
22+
expectType<unknown | undefined>(value);
23+
}));
24+
625
// GET
726
expectType<Promise<string | null>>(redis.get("key"));
827
expectType<Promise<Buffer | null>>(redis.getBuffer("key"));

0 commit comments

Comments
 (0)
Please sign in to comment.