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

Issues with typing on defered resolve method #146

Closed
shtaft opened this issue Sep 28, 2022 · 2 comments
Closed

Issues with typing on defered resolve method #146

shtaft opened this issue Sep 28, 2022 · 2 comments
Labels

Comments

@shtaft
Copy link

shtaft commented Sep 28, 2022

Hey team!
Thank you so much for maintaining this package, we are absolutely loving it.

We're in the process of upgrading to V2, and have noticed a small Typescript issue during the upgrade. It appears that deferring a resolve chain is not supported in the V2 types.

Here is a small repro:

import wretch from 'wretch'

const handle403 = () => {
  console.log('Unauthorized!')
}

const client = wretch('https://my-base-url.com')
  .defer((wretch) => {
    return wretch
        // Argument of type '(wretch: Wretch<unknown, unknown, undefined>) => Wretch<unknown, unknown, WretchResponseChain<unknown, unknown, undefined>>'
        // is not assignable to parameter of type 'WretchDeferredCallback<unknown, unknown, undefined>'
        .resolve((_) => _.forbidden(handle403));
  })

})
Argument of type '(wretch: Wretch<unknown, unknown, undefined>) => 
    Wretch<unknown, unknown, WretchResponseChain<unknown, unknown, undefined>>'
is not assignable to parameter of type 'WretchDeferredCallback<unknown, unknown, undefined>'

We like to modify requests made in the deferred callback, but can't in V2. Are we doing something wrong?

Thank you so much!

@elbywan elbywan added the bug label Sep 28, 2022
elbywan added a commit that referenced this issue Sep 28, 2022
@elbywan
Copy link
Owner

elbywan commented Sep 28, 2022

Hey @shtaft,

Thank you so much for maintaining this package, we are absolutely loving it.

Thanks, this is heartwarming 🙇.

We like to modify requests made in the deferred callback, but can't in V2. Are we doing something wrong?

No you're not 😉. There is definitely someting fishy with the return type of the .defer() function.
I just released version 2.1.4 which includes a fix and it should hopefully solve the problem.

Feel free to reopen the issue otherwise, and thanks for reporting the bug! 👍

@elbywan elbywan closed this as completed Sep 28, 2022
@shtaft
Copy link
Author

shtaft commented Sep 29, 2022

Unbelievable, thank you so much! Cannot believe your speed on resolving issues, incredible work.

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

No branches or pull requests

2 participants