Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IntersectionType and Prop decorator #2087

Closed
2 of 4 tasks
adostal opened this issue Mar 15, 2024 · 2 comments
Closed
2 of 4 tasks

IntersectionType and Prop decorator #2087

adostal opened this issue Mar 15, 2024 · 2 comments
Labels

Comments

@adostal
Copy link

adostal commented Mar 15, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When I use IntersectionType:

export class First {
  @Prop()
  first: string;
}

export class Second {
  @Prop()
 second: string;
}

export class Last extends IntersectionType(First, Second) {
 @Prop()
 last: string;
}

The problem is that properties like first and second are ignored.

const result = await this.model.create({
  first: 'First',
  second: 'Second',
  last: 'Last'
});

output:

{last: 'Last'}

Minimum reproduction code

https://github.com/nestjs/mongoose

Steps to reproduce

No response

Expected behavior

const result = await this.model.create({
  first: 'First',
  second: 'Second',
  last: 'Last'
});

output:

{first: 'First', second: 'Second', last: 'Last'}

Package version

10.0.4

mongoose version

8.0.2

NestJS version

10.3.3

Node.js version

21.7

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@adostal adostal added the bug label Mar 15, 2024
@prateekkathal
Copy link
Contributor

The classes from @nestjs/mapped-types only carry forward metadata declared by class-transformer and class-validator package based decorators. There is no mention in the docs that you can use it for @nestjs/mongoose class based schemas too.

I don't feel this is a bug. You'll just have to make amends to your code and follow a different hierarchal approach.

@kamilmysliwiec
Copy link
Member

As @prateekkathal mentioned above, IntersectionType utility function isn't supposed to be used with ODMs/ORMs and that's by design

@nestjs nestjs locked and limited conversation to collaborators Mar 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants