Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type system disagrees!!! #1572

Closed
LRagji opened this issue May 2, 2022 · 4 comments · Fixed by #1580
Closed

Type system disagrees!!! #1572

LRagji opened this issue May 2, 2022 · 4 comments · Fixed by #1580

Comments

@LRagji
Copy link

LRagji commented May 2, 2022

Using v5.0.4 with typescript like below and the multi command fails in compilation

const y = [
            ["set", "foo", "bar"],
            ["get", "foo"],
        ];

        const result = await this.redisClient.multi(y)
            .exec();

Error reported build time:(wigly under y in multi method)

No overload matches this call. Overload 1 of 4, '(options: { pipeline: false; }): Promise<"OK">', gave the following error. Argument of type 'string[][]' is not assignable to parameter of type '{ pipeline: false; }'. Property 'pipeline' is missing in type 'string[][]' but required in type '{ pipeline: false; }'. Overload 2 of 4, '(options: { pipeline: true; }): ChainableCommander', gave the following error. Argument of type 'string[][]' is not assignable to parameter of type '{ pipeline: true; }'. Property 'pipeline' is missing in type 'string[][]' but required in type '{ pipeline: true; }'. Overload 3 of 4, '(commands?: [name: string, ...args: unknown[]][]): ChainableCommander', gave the following error. Argument of type 'string[][]' is not assignable to parameter of type '[name: string, ...args: unknown[]][]'. Type 'string[]' is not assignable to type '[name: string, ...args: unknown[]]'. Source provides no match for required element at position 0 in target.ts(2769)

Where as following works without any issue:

const result = await this.redisClient.multi([ ["set", "foo", "bar"], ["get", "foo"], ]) .exec();

What am i doing wrong ?

@luin
Copy link
Collaborator

luin commented May 3, 2022

Hi @LRagji 👋

You are not doing anything wrong. It's should be a bug on ioredis's TypeScript declaration. Going to fix it in the next version.

For now, there are two workarounds:

const y: [name: string, ...args: string[]][] = [
  ["set", "foo", "bar"],
  ["get", "foo"],
];

const result = await this.redisClient.multi(y).exec();

Or

const result = await this.redisClient.multi([
    ["set", "foo", "bar"],
    ["get", "foo"],
  ])
  .exec();

@luin luin added the typing label May 3, 2022
@LRagji
Copy link
Author

LRagji commented May 3, 2022

Thanks @luin for confirming, i am using 3rd option //@ts-ignore 😜, but thats a weird type to typecast as well

@luin
Copy link
Collaborator

luin commented May 3, 2022

Aha I should have mentioned it. Actually you should use // @ts-expect-error so you can get notified once it's not needed.

@github-actions
Copy link

🎉 This issue has been resolved in version 5.0.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants