question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ParseArrayPipe `optional: true` returns unwanted default value `[ '' ]`

See original GitHub issue

Bug 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:closed
  • Created 2 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
jmcdo29commented, Aug 24, 2021
2reactions
jmcdo29commented, Aug 28, 2021

I’ll leave this here again: #7926 (comment)

Thankfully, micalevisk provided the repository that you requested so I thought I don’t have to do the exact same thing. Am I wrong? And apparently, this is now a matter of decision, not a bug. So you may close this issue unless you want to discuss further.

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found