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

Addon types are lost after passing through the handler #140

Closed
gwsbhqt opened this issue Aug 3, 2022 · 2 comments
Closed

Addon types are lost after passing through the handler #140

gwsbhqt opened this issue Aug 3, 2022 · 2 comments
Labels

Comments

@gwsbhqt
Copy link

gwsbhqt commented Aug 3, 2022

version 2.0.1

import { formUrlAddon } from 'wretch/addons'
import wretch from 'wretch'

export const fetch = wretch()
    .addon(formUrlAddon)
    .defer(w => w)
    .resolve(r => r.json())

export const fetch2 = wretch()
    .addon(formUrlAddon)
    .defer(w => w)
    .addon(formUrlAddon)
    .resolve(r => r.json())

export const fetch3 = wretch()
    .addon(formUrlAddon)
    .defer(w => w)
    .addon(formUrlAddon)
    .resolve(r => r.json())
    .headers({})

export const fetch4 = wretch()
    .addon(formUrlAddon)
    .defer(w => w)
    .addon(formUrlAddon)
    .resolve(r => r.json())
    .addon(formUrlAddon)
    .headers({})

image

error TS2684: The 'this' context of type 'Wretch<FormUrlAddon, unknown, undefined>' is not assignable to method's 'this' of type 'FormUrlAddon & Wretch<FormUrlAddon, unknown, undefined>'.

wretch/src/types.ts

Lines 314 to 318 in 4c4838d

defer<Clear extends boolean = false>(
this: Self & Wretch<Self, Chain, Resolver>,
callback: WretchDeferredCallback<Self, Chain, Resolver>,
clear?: Clear
): Wretch<Self, Chain, Resolver>

Self & Wretch<Self, Chain, Resolver> -> Wretch<Self, Chain, Resolver>
I found that every handler removes the self type, causes the next handler to fail to get the self type.
Is my understanding wrong?

@elbywan elbywan added the bug label Aug 3, 2022
@elbywan
Copy link
Owner

elbywan commented Aug 3, 2022

Hey @gwsbhqt, thanks for reporting the issue! 🙏

I found that every handler removes the self type, causes the next handler to fail to get the self type.
Is my understanding wrong?

On the contrary you're absolutely right, I'm pushing a fix right now and releasing 2.0.2 which should solve the problem.

elbywan added a commit that referenced this issue Aug 3, 2022
@gwsbhqt
Copy link
Author

gwsbhqt commented Aug 4, 2022

nice job, timely and effective support 😄

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