Skip to content

fix: @QueryParams() decorator doesn't trigger any type conversion #407

Closed
@gremo

Description

@gremo

Using @QueryParams() decorator doesn't trigger any type conversion (notice the number type) nor returns 400 for malformed/missing parameters:

class PagingOptions {
  limit = 10;
}

@JsonController('/test')
export class TestController {
  @Get('/foo')
  getAll(@QueryParams() params: PagingOptions) {
    console.log(params);
    return {};
  }
}

Call test/foo?limit=20 and console shows PagingOptions { limit: '20' } (notice the string type).

VS:

@JsonController('/test')
export class TestController {
  @Get('/bar')
  getAll2(@QueryParam('limit', { required: true }) limit: number) {
    console.log(limit);
    return {};
  }
}

Returns 400: Bad request when limit is missing; when present, it is converted to number.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: fixIssues describing a broken feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions