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

@Res() should accept type aliases for TsoaResponse #1666

Open
2 of 4 tasks
ltabis opened this issue Aug 27, 2024 · 3 comments · May be fixed by #1694
Open
2 of 4 tasks

@Res() should accept type aliases for TsoaResponse #1666

ltabis opened this issue Aug 27, 2024 · 3 comments · May be fixed by #1694

Comments

@ltabis
Copy link

ltabis commented Aug 27, 2024

Sorting

  • I'm submitting a ...

    • bug report
    • feature request
    • support request
  • I confirm that I

    • used the search to make sure that a similar issue hasn't already been submit

Expected Behavior

When typing my APIs, I noticed that I could type alias my TsoaResponse parameters since the same types are used in multiple routes.

export type NotFound = TsoaResponse<
  404,
  { reason: "Thing does not exists" }
>;

@Route("stuff")
export class MyController extends Controller {
  @Patch("{id}")
  public update(
    @Path() id: number,
    @Res() notExistsResponse: NotFound,
  ): Promise<any> {
    // update thing ... 
    return notExistsResponse(404, { reason: "Thing does not exists" });
  }

  @Get("{id}")
  public get(
    @Path() id: number,
    @Res() notExistsResponse: NotFound,
  ): Promise<any> {
    // get thing ... 
    return notExistsResponse(404, { reason: "Thing does not exists" });
  }
}

Current Behavior

However, the Res decorator seems to limit this to the TsoaResponse type without accepting aliases or extended interfaces.

Generate routes error.
2024-08-27 16:27:11 [1]  GenerateMetadataError: @Res() requires the type to be TsoaResponse<HTTPStatusCode, ResBody>
2024-08-27 16:27:11 [1] At: ...

Possible Solution

Let the Res decorator accept more types. Not sure how to do that since I am not that used to typescript.

Steps to Reproduce

See example above.

Context (Environment)

Version of the library: 6.4.0
Version of NodeJS: v20.12.2

  • Confirm you were using yarn not npm: [x]

Detailed Description

None

Breaking change?

Not sure

Copy link

Hello there ltabis 👋

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.👀

Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions bot added the Stale label Sep 27, 2024
@ltabis
Copy link
Author

ltabis commented Sep 27, 2024

👍

@github-actions github-actions bot removed the Stale label Sep 28, 2024
@jackey8616 jackey8616 linked a pull request Oct 3, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants