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.

OmitType "omits" @Transform decorators

See original GitHub issue

I’m submitting a…


[ ] Regression 
[x] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

I have a base class DTO for query params(using validation and @Transform decorators). When extending this with OmitType the validation decorators are taken into consideration, but not the @Transform. As a result, cannot create reusable objects and validation fails due to missing transformation(e.g from string to Date etc.)

Extending the class in the “normal” way it works like expected

Edit: Actually this seems to manifest when having a bigger class hierarchy QueryParamsDto ExtraQueryParamsDto extends QueryParamsDto FinalQueryParamsDto extends OmitType(ExtraQueryParamsDto, [‘some_property’])

It seems in the FinalQueryParamsDto tranformation decorators are not picked up if defined in the base class QueryParamsDto

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
shahen94commented, Feb 4, 2022

Seems still actual

"@nestjs/common": "^8.2.4",
"@nestjs/config": "^1.1.6",
"@nestjs/core": "^8.2.4",
"@nestjs/swagger": "^5.1.4",
export class FindAllQueryDto {
  @ApiPropertyOptional()
  @IsString()
  @IsOptional()
  userId?: string;

  @Transform(({ value }) => Array.isArray(value) ? value : [value])
  @ApiPropertyOptional()
  @IsString({ each: true })
  @IsOptional()
  enterprisesIds?: string[];
}

export class FilterUsersDto extends OmitType(FindAllQueryDto, ['userId']) {}

In the controller

@Get('users')
getUsers(@Query() query: FilterUsersDto) {
  console.log(query.enterprisesIds); // will not be converted array
}
curl http://localhost:3000/users?enterprisesIds=helloWorld

Expected

enterprisesIds should be [ 'helloWorld' ]

Actual

enterprisesIds equals helloWorld

0reactions
jmcdo29commented, Jul 20, 2022

If it’s still actually happened does someone want to provide a minimum reproduction repository like Kamil has already asked?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mapped Types - OpenAPI - A progressive Node.js framework
Omit #. The OmitType() function constructs a type by picking all properties from an input type and then removing a particular set of...
Read more >
Introducing Mapped Types for NestJS - Trilon Consulting
We've used the @ApiProperty() decorator to make properties ... Hint The OmitType() function is imported from the @nestjs/graphql package.
Read more >
Documentation - Utility Types - TypeScript
Omit<Type, Keys> ... Constructs a type by picking all properties from Type and then removing Keys (string literal or union of string literals)....
Read more >
ValidationPipes doesnt work with Body specific type
I think the problem is when i try to use Omit<SCHEMA, OMIT_VALUE> on body type, then i feels like my validator ignore my...
Read more >
typescript-cheatsheet - GitHub Pages
The cheatsheet contains references to types, classes, decorators, ... Omit type when extending an interface; Omitting specific properties when extending an ...
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