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

openapi-fetch Type instantiation is excessively deep and possibly infinite. #1882

Open
vovsemenv opened this issue Aug 28, 2024 · 2 comments
Labels
enhancement New feature or request good first issue Straightforward problem, solvable for first-time contributors without deep knowledge of the project openapi-fetch Relevant to the openapi-fetch library PRs welcome PRs are welcome to solve this issue!

Comments

@vovsemenv
Copy link

vovsemenv commented Aug 28, 2024

I have the code with 2 api calls - one with "openapi-fetch" other with "openapi-react-query"
but only "openapi-react-query" have actual error on paths that didn't exist,
"openapi-fetch"generates the Type instantiation is excessively deep and possibly infinite.

Because of that vscode autocomplete didn't work in case with "openapi-fetch"

import type { paths } from "app/typings/__generated/api";

import createFetchClient from "openapi-fetch";
import createClient from "openapi-react-query";

export const fetchClient = createFetchClient<paths>({});
export const $api = createClient(fetchClient);

fetchClient.GET("/api/d");
// ^ Type instantiation is excessively deep and possibly infinite.
$api.useQuery("get", "/api/sdf");
// ^ Argument of type '"/api/sdf"' is not assignable to parameter of type 'PathsWithMethod<paths, "get">'

fetchClient.GET("/api/accessgroup");
// ^ Existing url works fine
$api.useQuery("get", "/api/accessgroup");
// ^ Existing url works fine

api.d.ts.zip

@vovsemenv vovsemenv added bug Something isn't working openapi-fetch Relevant to the openapi-fetch library labels Aug 28, 2024
@drwpow drwpow added enhancement New feature or request PRs welcome PRs are welcome to solve this issue! good first issue Straightforward problem, solvable for first-time contributors without deep knowledge of the project and removed bug Something isn't working labels Sep 2, 2024
@drwpow
Copy link
Contributor

drwpow commented Sep 2, 2024

As you discerned, this error does appear when there’s an actual error. It’s tough to control the output for what TypeScript shows beyond throwing an error. There are no known instances where this happens for a legitimate path. But agreed the error could be more helpful.

Flagged as an “enhancement” as in “this error message should be improved” although we are limited by what TypeScript allows (since it’s the one that shows that error). PRs are welcome for anyone that can improve this! (And bonus points if it can be tested)

@vovsemenv
Copy link
Author

Yes i understand that😅 Just really strange to see that the same thing works in react-query version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Straightforward problem, solvable for first-time contributors without deep knowledge of the project openapi-fetch Relevant to the openapi-fetch library PRs welcome PRs are welcome to solve this issue!
Projects
None yet
Development

No branches or pull requests

2 participants