Skip to content

Commit

Permalink
fix: Add back Pipeline#length (#1585)
Browse files Browse the repository at this point in the history
Closes #1584
  • Loading branch information
luin authored May 31, 2022
1 parent fe21620 commit 63b2ee4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
5 changes: 3 additions & 2 deletions bin/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ export interface ResultTypes<Result, Context> {
pipeline: ChainableCommander;
}

export interface ChainableCommander
extends RedisCommander<{ type: "pipeline" }> {}
export interface ChainableCommander extends RedisCommander<{ type: "pipeline" }> {
length: number;
}

export type ClientContext = { type: keyof ResultTypes<unknown, unknown> };
export type Result<T, Context extends ClientContext> =
Expand Down
4 changes: 4 additions & 0 deletions lib/Pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,7 @@ Pipeline.prototype.exec = function (callback: Callback): Promise<Array<any>> {
return _this.promise;
}
};

interface Pipeline {
length: number;
}
5 changes: 3 additions & 2 deletions lib/utils/RedisCommander.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ export interface ResultTypes<Result, Context> {
pipeline: ChainableCommander;
}

export interface ChainableCommander
extends RedisCommander<{ type: "pipeline" }> {}
export interface ChainableCommander extends RedisCommander<{ type: "pipeline" }> {
length: number;
}

export type ClientContext = { type: keyof ResultTypes<unknown, unknown> };
export type Result<T, Context extends ClientContext> =
Expand Down
11 changes: 10 additions & 1 deletion test/typing/pipeline.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expectType } from "tsd";
import Redis from "../../built";
import Redis, { Pipeline } from "../../built";

const redis = new Redis();

Expand All @@ -24,3 +24,12 @@ expectType<RETURN_TYPE>(
])
.exec()
);

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

expectType<number>(({} as unknown as Pipeline).length);

0 comments on commit 63b2ee4

Please sign in to comment.