mapped-types icon indicating copy to clipboard operation
mapped-types copied to clipboard

IntersectionType breaks returning value of methods

Open maioradv opened this issue 2 years ago • 4 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current behavior

I'm trying to interect two classes to obtain a dto like that:

export class QueryPageDto extends IntersectionType(PartialType(OmitType(CreatePageDto,['metafields','translations'])),PaginationDTO) {}
export default class PaginationDTO {
  @ApiProperty({
    minimum: 1,
    default: 1,
  })
  @IsNumber()
  @IsOptional()
  @IsInt()
  @Min(1)
  @Type(() => Number)
  readonly page?:number = 1;

  @ApiProperty({
    minimum: 1,
    maximum: 250,
    default: 50,
  })
  @IsNumber()
  @IsOptional()
  @IsInt()
  @Min(1)
  @Max(250)
  @Type(() => Number)
  readonly limit?:number = 50;

  get skip(): number {
    return (this.page - 1) * this.limit;
  }

  get take(): number {
    return this.limit;
  }
}

but when i type queryPageDto.skip (or take) also if is suggested they always returns undefined i tried that whitout IntersectionType and obviously works.

Minimum reproduction code

https://github.com

Steps to reproduce

No response

Expected behavior

I'm expecting returning values

Package version

2.0.5

Node.js version

20.11.0

In which operating systems have you tested?

  • [ ] macOS
  • [X] Windows
  • [ ] Linux

Other

"@nestjs/mapped-types": "*", "@nestjs/swagger": "^7.2.0",

maioradv avatar Feb 16 '24 14:02 maioradv

Please provide a minimum reproduction repository (Git repository/StackBlitz/CodeSandbox project).

why reproductions are required

jmcdo29 avatar Feb 16 '24 16:02 jmcdo29

Try /test

https://codesandbox.io/p/devbox/brave-christian-c22g5q?layout=%257B%2522sidebarPanel%2522%253A%2522EXPLORER%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522clssokgns0007356hb14awecx%2522%252C%2522sizes%2522%253A%255B70%252C30%255D%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522id%2522%253A%2522clssokgnr0002356hexe3ch7w%2522%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522SHELLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522id%2522%253A%2522clssokgnr0004356hzvmciyvx%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522DEVTOOLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522id%2522%253A%2522clssokgns0006356h6j4h35i9%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%252C%2522sizes%2522%253A%255B50%252C50%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522clssokgnr0002356hexe3ch7w%2522%253A%257B%2522id%2522%253A%2522clssokgnr0002356hexe3ch7w%2522%252C%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clssokgnq0001356hye8i8apd%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522FILE%2522%252C%2522filepath%2522%253A%2522%252FREADME.md%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%255D%252C%2522activeTabId%2522%253A%2522clssokgnq0001356hye8i8apd%2522%257D%252C%2522clssokgns0006356h6j4h35i9%2522%253A%257B%2522id%2522%253A%2522clssokgns0006356h6j4h35i9%2522%252C%2522tabs%2522%253A%255B%257B%2522type%2522%253A%2522TASK_PORT%2522%252C%2522taskId%2522%253A%2522start%253Adev%2522%252C%2522port%2522%253A3000%252C%2522id%2522%253A%2522clssp04fw01aw356hnm8a1wag%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522path%2522%253A%2522%2522%257D%255D%252C%2522activeTabId%2522%253A%2522clssp04fw01aw356hnm8a1wag%2522%257D%252C%2522clssokgnr0004356hzvmciyvx%2522%253A%257B%2522id%2522%253A%2522clssokgnr0004356hzvmciyvx%2522%252C%2522activeTabId%2522%253A%2522clssozwfa0184356h0yysnrc7%2522%252C%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clssorj3300vu356hlya0u1s5%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TERMINAL%2522%252C%2522shellId%2522%253A%2522clssoqc0y006xdjq4cu2zgsc2%2522%257D%252C%257B%2522type%2522%253A%2522TASK_LOG%2522%252C%2522taskId%2522%253A%2522start%253Adev%2522%252C%2522id%2522%253A%2522clssozwfa0184356h0yysnrc7%2522%252C%2522mode%2522%253A%2522permanent%2522%257D%255D%257D%257D%252C%2522showDevtools%2522%253Atrue%252C%2522showShells%2522%253Atrue%252C%2522showSidebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D

maioradv avatar Feb 19 '24 09:02 maioradv

Looks like your issue is that the IntersectionType removes the getters that you have set, which I believe is the expected behavior, right @kamilmysliwiec?

jmcdo29 avatar Feb 19 '24 18:02 jmcdo29

That's correct @jmcdo29

kamilmysliwiec avatar Feb 20 '24 07:02 kamilmysliwiec