hey-api / openapi-ts

✨ Turn your OpenAPI specification into a beautiful TypeScript client
https://heyapi.vercel.app
MIT License
634 stars 44 forks source link

CancelablePromise type does not work with react suspense #678

Closed that-ambuj closed 4 days ago

that-ambuj commented 2 weeks ago

Description

The generated CancelablePromise does not work with React Suspense. I think the issue is that the type does not serialize properly after being completed. The reason could be that this custom type is not compatible with different runtimes or react only works with the traditional Promise type.

Is there any way I can generated code that returns a regular Promise<T> instead of CancelablePromise<T>?

OpenAPI specification (optional)

No response

Configuration

No response

System information (optional)

No response

that-ambuj commented 2 weeks ago

I found a Hack, I can pass the .promise field as the promise required.

This is kind of a gotcha that had me for the last 2 hours. I hope you mention it in the docs.

mrlubos commented 2 weeks ago

@that-ambuj You could try using the new Fetch API client?

that-ambuj commented 2 weeks ago

I did not pass any --client option to the script, it's the default one right?

mrlubos commented 2 weeks ago

No https://heyapi.vercel.app/openapi-ts/clients.html#legacy-clients

that-ambuj commented 1 week ago

In fact, @hey-api/openapi-ts still generates a legacy Fetch API client by default. You can generate other legacy clients with the client config option.

@mrlubos This is kind of confusing, don't you think?