ParseArrayPipe `optional: true` returns unwanted default value `[ '' ]`
See original GitHub issueBug Report
Current behavior
console.log(tagIds);
prints [ '' ]
regardless of DefaultValuePipe
. If optional
is false, it throws Bad Request exception “Validation failed (parsable array expected)”.
Input Code
@Get()
findSomething(
@Query(
'tagIds',
new DefaultValuePipe([]),
new ParseArrayPipe({ items: Number, optional: true }),
)
tagIds: number[],
) {
console.log(tagIds);
// return something
}
Expected behavior
I should be undefined
or empty array []
.
Possible Solution
Environment
Nest version: 7.6.18
For Tooling issues:
- Node version: 12.18.0
- Platform: Mac
Others:
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (7 by maintainers)
Top Results From Across the Web
Define random default value in class-validator for each ...
It's not true that you can only send back static values in the DTO. You can simply do this: class CreateUserDto { @IsOptional()...
Read more >Announcing NestJS 7: What's New - Trilon Consulting
Today I am excited to announce the official release of Nest 7: A progressive Node.js framework for building efficient and enterprise-grade, ...
Read more >Fixing validation error in NestJS when using ...
In my application I return the entity model directly for GET requests and I like having arrays as empty instead of undefined properties....
Read more >Guide to Nest.js - Building a REST API with Nest and Node
In this guide, learn the basics of NestJS - dependency injection, building a REST API, handling redirects and dynamic routing, etc. with ...
Read more >What's New in NestJS 7? - Morioh
With the auto-transformation option enabled ( transform: true ) ... Notice that the return value of Call which is a MaybeHandle<Object> will be...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ll leave this here again: https://github.com/nestjs/nest/issues/7926#issuecomment-904097118
When I wrote the original comment, the repository had not been added, or I had missed it because edits don’t show up in emails and I had already been following the conversation. Seeing as we have a reproduction, I can take a look later myself. Thanks for pointing out out