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

Typings seems incorrect #19

Closed
sinedied opened this issue May 15, 2020 · 3 comments · Fixed by #22
Closed

Typings seems incorrect #19

sinedied opened this issue May 15, 2020 · 3 comments · Fixed by #22

Comments

@sinedied
Copy link

Maybe I missed something, but the function returned by throttle is not type-compatible with the original, which seems kinda wrong.

I'm trying to do something like this:

const throttledPost = pThrottle(got.post, 10, 30000);
...
const post = shouldThrottle ? throttledPost : got.post; // ts error here, incompatible types
post('/some/api, ...);

Is there something I missed, like a providing types for pThrottle or is this a bug?
Thanks for helping.

@sindresorhus
Copy link
Owner

It is intended to be type-compatible, yes.

@misha-erm
Copy link

misha-erm commented Dec 3, 2020

Hi, is there any workaround right now how to use p-throttle with got?

Tried to do few options, but failed since it looses possibility to pass generic.
1.

const throttledFetch = pThrottle(got, REQ_PER_10_SEC, RATE_INTERVAL);

throttledFetch<{res: boolean}>('url'); //expected 0 type arguments
const throttledFetch = pThrottle<Parameters<typeof got>, ReturnType<typeof got>>(got, REQ_PER_10_SEC, RATE_INTERVAL);

throttledFetch<{res: boolean}>('url'); //expected 0 type arguments
const throttledFetch = <R>() => pThrottle<Parameters<typeof got>, R>(got, REQ_PER_10_SEC, RATE_INTERVAL); //error here. Argument of type 'Got' is not assignable to parameter of type '(options: Options) => R | PromiseLike<R>'

Thanks in advance

@misha-erm
Copy link

For now I did this, but it feels sooo wrong )

const throttledFetch = (pThrottle(
        got,
        RES_PER_10_SEC,
        RATE_INTERVAL,
    ) as unknown) as typeof got;

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.

3 participants