-
-
Notifications
You must be signed in to change notification settings - Fork 529
parseAs doesn't change the data type #1370
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
Comments
Thanks for suggesting! I think perhaps a more full code example of the desired end-user usage could help me (and others) understand? Including a snippet of the original OpenAPI schema, as well as highlighting before/after code would clarify the exact change being proposed. |
@drwpow const reponseText = await api.GET('/path', { parseAs: 'text' });
reponseText.data; // the type is whatever JSON is returned from this route, but in reality the type is string The same applies for any other |
Ah I understand. What does the OpenAPI schema look like? Does it still have JSON typing as well as other media types? |
@drwpow I found an example in your tests - you check if data is equal for {
email: string;
age?: number | undefined;
avatar?: string | undefined;
} | undefined But the test passes. It's not an edge case with my schema - it's just that coreFetch return type does not depend on provided |
@drwpow so would you like for me to try to work on this? If yes which of the two approaches(in the original post) would you prefer? |
There’s an internal change I’d like to make where the runtime code is separated from the type definitions (separate, and manually-managed Anyways, all that said, I need to make that change before we tackle this problem, as that will make this much easier. I’d welcome a PR once that change is in! |
Just made that change (#1424) so I’d welcome a PR on this! With the split, you’d only have to make a change in Overall I don’t have a strong opinion between either option, but 1 seems preferable. This library is still |
Ok, working on it now. |
Description
Specifying
parseAs
as "string" or even "stream" still specifiesdata
as JSONProposal
A new generic parameter could be added to
coreFetch
to infer correct return type.FetchResponse
,FetchOptions
and the types it uses accordingly. This would technically be breaking for people who use these types in their codebase. We can instead of adding a third type parameter just modify the second one - something likeO extends {method: HttpMethod, parseAs: ParseAs}
.coreFetch
, then adding a second optional type parameter with a default value forFetchOptions
andRequestOptions
. And then also modify the return type ofcoreFetch
directly instead of modifyingFetchResponse
type - something likeFirst approach seems more "correct" but is breaking in a sense. The second one feels like a band-aid but shouldn't affect users.
Checklist
The text was updated successfully, but these errors were encountered: