Skip to content

All return types from schema are <type> | undefined #1201

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

Closed
dino-rodriguez opened this issue Jul 6, 2023 · 1 comment
Closed

All return types from schema are <type> | undefined #1201

dino-rodriguez opened this issue Jul 6, 2023 · 1 comment
Labels
bug Something isn't working openapi-fetch Relevant to the openapi-fetch library

Comments

@dino-rodriguez
Copy link

All of the return types from my schema are the return type | undefined.

In my open API compliant API, the return types of the functions are not optional, they are required. How can I make this all return the required types instead of optional types in open API fetch?

e.g. the output type of data of a call like this:

const { data } = await post('/v1/example_endpoint', {
    body: {}
  });

is

{ message: string } | undefined
@dino-rodriguez dino-rodriguez added bug Something isn't working openapi-fetch Relevant to the openapi-fetch library labels Jul 6, 2023
@drwpow
Copy link
Contributor

drwpow commented Jul 6, 2023

It’s | undefined because you haven’t checked for the existence of error yet. Once you’ve handled error, then data will always be defined. This is to make sure your error messages are shown to the user / handled properly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi-fetch Relevant to the openapi-fetch library
Projects
None yet
Development

No branches or pull requests

2 participants