Skip to content

Commit f9f875b

Browse files
authored
fix: improve typing for redis.multi (#1580)
1 parent 7a9e5fd commit f9f875b

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

Diff for: lib/transaction.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { Callback } from "./types";
55
import { ChainableCommander } from "./utils/RedisCommander";
66

77
export interface Transaction {
8-
pipeline(commands?: [name: string, ...args: unknown[]][]): ChainableCommander;
8+
pipeline(commands?: unknown[][]): ChainableCommander;
99
multi(options: { pipeline: false }): Promise<"OK">;
1010
multi(): ChainableCommander;
1111
multi(options: { pipeline: true }): ChainableCommander;
12-
multi(commands?: [name: string, ...args: unknown[]][]): ChainableCommander;
12+
multi(commands?: unknown[][]): ChainableCommander;
1313
}
1414

1515
export function addTransactionSupport(redis) {

Diff for: test/typing/pipeline.test-d.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,24 @@ import Redis from "../../built";
33

44
const redis = new Redis();
55

6-
expectType<Promise<[Error | null, unknown][] | null>>(
7-
redis.pipeline().set("foo", "bar").get("foo").exec()
8-
);
6+
type RETURN_TYPE = Promise<[Error | null, unknown][] | null>;
7+
8+
expectType<RETURN_TYPE>(redis.pipeline().set("foo", "bar").get("foo").exec());
99

10-
expectType<Promise<[Error | null, unknown][] | null>>(
10+
expectType<RETURN_TYPE>(
1111
redis
1212
.pipeline([
1313
["set", "foo", "bar"],
1414
["get", "foo"],
1515
])
1616
.exec()
1717
);
18+
19+
expectType<RETURN_TYPE>(
20+
redis
21+
.pipeline([
22+
["set", Buffer.from("foo"), "bar"],
23+
["incrby", "foo", 42],
24+
])
25+
.exec()
26+
);

0 commit comments

Comments
 (0)