-
Notifications
You must be signed in to change notification settings - Fork 86
Description
Description
The zremrangebyscore command has incorrect TypeScript type definitions that only accept number for min and max parameters, but the Redis protocol (and Upstash REST API) accept string values like '-inf' and '+inf'.
Current Type Definition
export class ZRemRangeByScoreCommand extends Command<number, number> {
constructor(cmd: [key: string, min: number, max: number], opts?: CommandOptions<number, number>)
}Expected Type Definition
export class ZRemRangeByScoreCommand extends Command<number, number> {
constructor(cmd: [key: string, min: number | string, max: number | string], opts?: CommandOptions<number, number>)
}Justification
-
Redis Protocol Support: Redis
ZREMRANGEBYSCOREaccepts special string values:'-inf'for negative infinity'+inf'for positive infinity'(value'for exclusive ranges
-
Consistency with Other Commands: The
ZCountCommandalready usesmin: number | string, max: number | string(see zcount.ts), making this an inconsistency in the codebase. -
Runtime vs Types Mismatch: The Upstash REST API already accepts these string values at runtime, but TypeScript types force developers to use type assertions.
Evidence
This works at runtime but requires a type workaround:
// Current workaround required
// @ts-expect-error - Upstash types only show number, but runtime accepts strings
await redis.zremrangebyscore('mykey', '-inf', Date.now() - 900000);
// OR with String() conversion
await redis.zremrangebyscore('mykey', String('-inf'), String(Date.now() - 900000));Proposed Fix
Update type definitions in pkg/commands/zremrangebyscore.ts:
export class ZRemRangeByScoreCommand extends Command<number, number> {
- constructor(cmd: [key: string, min: number, max: number], opts?: CommandOptions<number, number>) {
+ constructor(cmd: [key: string, min: number | string, max: number | string], opts?: CommandOptions<number, number>) {
super(["zremrangebyscore", ...cmd], opts);
}
}References
- Redis
ZREMRANGEBYSCOREcommand: https://redis.io/commands/zremrangebyscore/ - Upstash TypeScript SDK docs: https://upstash.com/docs/redis/sdks/ts/commands/zset/zremrangebyscore
- Consistent implementation in
zcount.ts: https://github.com/upstash/redis-js/blob/main/pkg/commands/zcount.ts
I'm preparing a PR to fix this issue.