redis / ioredis

🚀 A robust, performance-focused, and full-featured Redis client for Node.js.
MIT License
14.07k stars 1.19k forks source link

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

Open ericrav opened 10 months ago

ericrav commented 10 months ago

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"'.
rwky3gtelecoms commented 9 months ago

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

anthony-langford commented 3 months ago

I just ran into this issue as well

Jiia commented 1 month ago

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