Skip to content

[WIP] Support Observable return types for Nestia SDK #1358

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 8, 2025

Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.

Original issue description:

Feature Request

When using the Nestia Client SDK, it can properly infer the controller method return value types when returning synchronously or returning a Promise. However, if we try to return an Observable, then the SDK is not able to generate types properly.

Since NestJS has first-class support for Observables, many times we work with Observables exclusively and would just like to return the Observable from the controller method instead of converting it to a Promise and then returning the Promise. However, returning an Observable type breaks Nestia's ability to properly type the response type.

Workaround's we need to use today:

  1. Use async / await and only work with Promises
  2. Use the firstValueFrom rxjs operator to convert Observable to Promise before returning the response from the controller.

This works fine:

   @TypedRoute.Get('user/:id')
   async getUser(@Param('id') id: string): Promise<User> {
     return firstValueFrom(this.userService.findById(id));
   }

This does not:

   @TypedRoute.Get('user/:id')
   getUser(@Param('id') id: string): Observable<User> {
     return this.userService.findById(id);
   }

Fixes #747.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

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.

Support Observable return types for Nestia SDK
2 participants