tsoa icon indicating copy to clipboard operation
tsoa copied to clipboard

Allow parameter decorators to be used as method decorators instead to allow usage in ECMA decorator enabled projects

Open sinomsinom opened this issue 4 months ago • 0 comments

Sorting

  • I'm submitting a ...

    • [ ] bug report
    • [X] feature request
    • [ ] support request
  • I confirm that I

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

Expected Behavior

Allow decorators to be used like this:

    @Get('some/{someId}/path
    @Path('id', 'someId')
    @Request('req')
    @Body('body')
    public async someEndpoint(
        id: string,
        body: {someField:number},
        req: express.Request
    ) {
        ...
    }

To allow for usage in projects with ECMA decorators enabled since they don't support parameter decorators.

Current Behavior

Currently you need to always use ts-expect-error before every parameter used, and even that only works with select typescript transpilers.

Current code:

    @Get('some/{someId}/path
    public async someEndpoint(
        //@ts-expect-error(TS1206)
        @Path('someId') id: string,
        //@ts-expect-error(TS1206)
        @Body() body: {someField:number},
        //@ts-expect-error(TS1206)
        @Request('req') req: express.Request
    ) {
        ...
    }

Context (Environment)

Version of the library: 6.4.0 Version of NodeJS: v22.4.1

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

Detailed Description

The reason ignoring the error works in the first place is because all the parameter decorators are no-ops already and are only read by the preprocessor/generator as what basically equates to comments. The only type of decorator in tsoa that isn't a no-op is the Middleware decorator though that isn't a parameter decorator so would be a separate issue.

Breaking change?

This would be an additional optional way of using the decorators so it would not be a breaking change with any current projects. Also changing the Middleware decorator WOULD be a breaking change, however simply adding an alternative decorator for use in ECMA decorator projects would completely mitigate that issue making it a non breaking change.

sinomsinom avatar Oct 04 '24 07:10 sinomsinom