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
fix(nuxt): infer useFetch
method when generic is passed
#20797
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you be able to add a test case in test/fixtures/basic/types.ts
that was failing before this PR?
@danielroe I added one, btw, setting the return type and request method explicitly will easily reproduce. |
Thanks! I've gone ahead and pushed a failing test to show why the type is written as is. |
@@ -31,7 +31,7 @@ export function useFetch< | |||
ResT = void, | |||
ErrorT = FetchError, | |||
ReqT extends NitroFetchRequest = NitroFetchRequest, | |||
Method extends AvailableRouterMethod<ReqT> = 'get' extends AvailableRouterMethod<ReqT> ? 'get' : AvailableRouterMethod<ReqT>, | |||
Method extends AvailableRouterMethod<ReqT> = AvailableRouterMethod<ReqT>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about this instead?
Method extends AvailableRouterMethod<ReqT> = AvailableRouterMethod<ReqT>, | |
Method extends AvailableRouterMethod<ReqT> = ResT extends void ? 'get' extends AvailableRouterMethod<ReqT> ? 'get' : AvailableRouterMethod<ReqT> : AvailableRouterMethod<ReqT>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! You are right. I have updated it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also find the reason of broken type when passing uppercase method, maybe its a nitro type error in fetch.ts
.
Another PR in nitro
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work - thanks! I think we can go ahead and merge this PR (as it fixes one issue without introducing any regressions) and then update test once nitro PR is merged..
useFetch
method when generic is passed
π Linked issue
resolves #19077
β Type of change
π Description
I provided a workaround before, but this issue doesn't get solved.
I find that just change the method type
'get' extends AvailableRouterMethod<ReqT> ? 'get' : AvailableRouterMethod<ReqT>
intoAvailableRouterMethod<ReqT>
, and all works fine as I seeπ Checklist