nestjs / mapped-types

Configuration module for Nest framework (node.js) 🐺
https://nestjs.com
MIT License
375 stars 58 forks source link

`PickType` doesn't carry over property level`@Expose` decorators #1369

Open erikash opened 6 months ago

erikash commented 6 months ago

Is there an existing issue for this?

Current behavior

class TestDto {
  firstname: string;
  lastname: string;

  @Expose({ toPlainOnly: true })
  get fullName() {
    return `${this.firstname} ${this.lastname}`;
  }
}

class PickTestDto extends PickType(TestDto, [] as const) {}

@Get('picktype')
  getPickTypeTest(): TestDto {
    const instance = plainToInstance(PickTestDto, {
      firstname: 'John',
      lastname: 'Doe',
    });

    const plain = instanceToPlain(instance);

    return plain as unknown as TestDto;
  }

The API returns: {"firstname":"John","lastname":"Doe"}

Minimum reproduction code

https://github.com/erikash/picktype

Steps to reproduce

  1. pnpm start:dev
  2. curl http://localhost:3000/picktype

use this to see the expected result

  1. curl http://localhost:3000/inheritence

Expected behavior

I would expect the Expose on get fullName to be inherited and the API to return{"firstname":"John","lastname":"Doe","fullName":"John Doe"} as per step 3) above.

Package version

2.0.5

Node.js version

18.17.1

In which operating systems have you tested?

Other

No response