Skip to content

Commit

Permalink
fix: improve typing for redis.multi (#1580)
Browse files Browse the repository at this point in the history
  • Loading branch information
luin authored May 17, 2022
1 parent 7a9e5fd commit f9f875b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { Callback } from "./types";
import { ChainableCommander } from "./utils/RedisCommander";

export interface Transaction {
pipeline(commands?: [name: string, ...args: unknown[]][]): ChainableCommander;
pipeline(commands?: unknown[][]): ChainableCommander;
multi(options: { pipeline: false }): Promise<"OK">;
multi(): ChainableCommander;
multi(options: { pipeline: true }): ChainableCommander;
multi(commands?: [name: string, ...args: unknown[]][]): ChainableCommander;
multi(commands?: unknown[][]): ChainableCommander;
}

export function addTransactionSupport(redis) {
Expand Down
17 changes: 13 additions & 4 deletions test/typing/pipeline.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,24 @@ import Redis from "../../built";

const redis = new Redis();

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

expectType<RETURN_TYPE>(redis.pipeline().set("foo", "bar").get("foo").exec());

expectType<Promise<[Error | null, unknown][] | null>>(
expectType<RETURN_TYPE>(
redis
.pipeline([
["set", "foo", "bar"],
["get", "foo"],
])
.exec()
);

expectType<RETURN_TYPE>(
redis
.pipeline([
["set", Buffer.from("foo"), "bar"],
["incrby", "foo", 42],
])
.exec()
);

0 comments on commit f9f875b

Please sign in to comment.