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

Optional return value definition does not include undefined #148

Open
invliD opened this issue Oct 2, 2020 · 3 comments
Open

Optional return value definition does not include undefined #148

invliD opened this issue Oct 2, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@invliD
Copy link
Member

invliD commented Oct 2, 2020

What happened?

A method with an optional return value gets generated as method(…): Promise<T | null>. That's correct if the server returns a JSON result of null. If the server responds with a 204 instead, the return value is undefined as the runtime is currently implemented. An alternative would be to change the runtime to return null in the 204 case, but I believe the runtime is correct here since 204 means "no content", which I'd translate as "the return value is not defined".

What did you want to happen?

The correct definition encompassing both cases should be method(…): Promise<T | null | undefined>.

@uschi2000
Copy link

in most cases, an empty conjure optional<> return value means "the requested object does not exist", which I think is closer to null than to undefined. there might be other uses of conjure optional<>, but I think this is the most common.

@invliD
Copy link
Member Author

invliD commented Oct 2, 2020

I don't think we can distinguish a method returning optional.absent from a method returning nothing (i.e. having no return type), since we don't have the relevant part of the conjure definition at runtime. If we switched the meaning of 204 over to null, we'd have methods typed as Promise<void> actually return Promise<null>, which is a similar bug in the opposite direction. Methods returning void return no value. If you try to access the value anyway, it is undefined.

@uschi2000
Copy link

ok, this is beyond my typescript knowledge, but I agree there's a bug

@invliD invliD added the bug Something isn't working label Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants