ioredis icon indicating copy to clipboard operation
ioredis copied to clipboard

TypeScript overloads for `set` doesn't allow `NX` together with expiration tokens

Open ericrav opened this issue 1 year ago • 4 comments

For example:

redis.set('key', 'value', 'NX', 'EX', 1000);

results in:

No overload matches this call.
  The last overload gave the following error.
    Argument of type '"NX"' is not assignable to parameter of type '"KEEPTTL"'.

ericrav avatar Sep 05 '23 18:09 ericrav

If you swap the arguments so it's redis.set('key', 'value', 'EX', 1000, 'NX'); it works, though this isn't how the redis docs describe the command https://redis.io/commands/set/ this is the definition that's causing it

  set(
    key: RedisKey,
    value: string | Buffer | number,
    secondsToken: "EX",
    seconds: number | string,
    nx: "NX",
    callback?: Callback<"OK" | null>
  ): Result<"OK" | null, Context>;

https://raw.githubusercontent.com/redis/ioredis/main/lib/utils/RedisCommander.ts

rwky3gtelecoms avatar Sep 25 '23 00:09 rwky3gtelecoms

I just ran into this issue as well

anthony-langford avatar Mar 26 '24 19:03 anthony-langford

Yep, the only way to do it the officially documented way is to add @ts-ignore, which is really bad practice.

Jiia avatar May 21 '24 09:05 Jiia

I just ran into this issue as well

amitp-gc avatar Jul 11 '24 06:07 amitp-gc