Closed jsanson98 closed 1 year ago
That is a known limitation of typescript metadata reflection :/
@micalevisk can you provide any more insight? If ?
doesn't work, shouldn't | undefined
still work? Are there specific limitations around method argument types that don't apply to class property types?
@chriskuech at runtime, there's no way to infer that that parameter is optional.
Using | undefined
won't even report that parameterto th just because x | undefined
is a type notation. And type notations are erased by typescript compiler. The same lies to | null
I don't recall where you can learn more those limitations of reflect-metadata
, sorry. But isn't related with nestjs itself.
Is there an existing issue for this?
Current behavior
When setting a
@Query
param in a@Get
and defining that param as possibly undefined, the args type for that query are created as if that field is mandatory.Ex:
@Query('skip') skip?: number
Arg created as:
A fix is to add:
@ApiQuery({ name: 'skip', required: false, type: Number })
. But it's not desired.Minimum reproduction code
https://stackblitz.com/edit/nestjs-typescript-starter-ipnkdc?file=src%2Fapp.controller.ts
Steps to reproduce
No response
Expected behavior
The arg should be created as:
Package
Other package
No response
NestJS version
No response
Packages versions
Node.js version
No response
In which operating systems have you tested?
Other
No response