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

fix: only return Observable types for NestJS if the option is switched on #823

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

alexkb
Copy link

@alexkb alexkb commented May 4, 2023

We're using --ts_proto_opt=nestjs=true and wanted to remove Observable's being returned, so we tried --ts_proto_opt=returnObservable=false but it had no effect.

This PR fixes that issue so it does behave as expected. If it is incorrect, then I suggest you update the documentation to make it clear that returnObservable has no effect when nestjs=true. Thanks.

@alexkb alexkb changed the title Only return Observavle types for NestJS if the option is switched on fix: only return Observable types for NestJS if the option is switched on May 4, 2023
@tmthecoder
Copy link

Bump on this, using nestJS currently doesn't allow me to generate methods returning a promise

@alexkb
Copy link
Author

alexkb commented Oct 23, 2023

@tmthecoder if you've got --ts_proto_opt=nestJs=true set then you should get Promise's along with Observable's, which you don't have to use. You won't get them though, if you've also set ts_proto_opt=returnObservable=true OR if your methods involve streams. Whatever the case, I've just re-synced this branch with main but I'm not sure what the maintainer wants to do here sorry.

@tmthecoder
Copy link

tmthecoder commented Oct 23, 2023

@alexkb I see the types be promise or observable for the controller implementations but the clients only have observable in the definitions, not sure why that is. I have the observable flag set to false manually in the proto gen command


findManyVillain(request: Observable<VillainById>): Observable<Villain>;

findManyVillainStreamIn(request: Observable<VillainById>): Promise<Villain> | Observable<Villain> | Villain;
findManyVillainStreamIn(request: Observable<VillainById>): Promise<Villain> | Villain;
Copy link
Owner

@stephenh stephenh Oct 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexkb Disclaimer that I don't use NestJS, but wouldn't just Promise<Villain> make more sense here as a return type?

I agree that your PR is already better than the previous Observable<T> | Promise<T> | T, which imo seems just kind of maddening to use as a caller, b/c you'd have to constantly be checking what the return value was.

...ah, maybe this interface is meant for the server-side to implement, and we want to give flexibility to the server to return what it wants.

Are these interfaces used by both the client and the server? I don't remember...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants