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

extends with OmitType removes methods from Base class #471

Closed
mohsensaremi opened this issue Sep 22, 2021 · 3 comments
Closed

extends with OmitType removes methods from Base class #471

mohsensaremi opened this issue Sep 22, 2021 · 3 comments

Comments

@mohsensaremi
Copy link

I'm submitting a...


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

Current behavior

When extends using OmitType(), the derived class does not contain Base class methods.

Expected behavior

Expect derived class to have parent class methods

Minimal reproduction of the problem with instructions

import { IsString } from 'class-validator';
import { OmitType } from '@nestjs/mapped-types';
import { plainToClass } from 'class-transformer';

class BaseClass {
  @IsString()
  a: string;

  @IsString()
  b: string;

  someMethod() {
    return 'this is a method';
  }
}

class DerivedClass extends OmitType(BaseClass, ['a']) {}

const instance = plainToClass(DerivedClass, {
  b: 'some value',
});

console.log(instance.someMethod());

expect this code to log this is a method but it will throw the following error:

console.log(instance.someMethod());
                     ^
TypeError: instance.someMethod is not a function
...

What is the motivation / use case for changing the behavior?

It should work as normal extends.

Environment


Nest version: ^8.0.0
@nestjs/mapped-types:  ^1.0.0

 
For Tooling issues:
- Node version: v14.16.1
- Platform:  Mac

Others:

@micalevisk
Copy link
Member

This is expected since methods are just properties.

Thus, you must do something like OmitType(BaseClass, ['a', 'someMethod'])

@mohsensaremi
Copy link
Author

@micalevisk
I want to someMethod inherit from BaseClass but you Omit it!
Using OmitType(BaseClass, ['a', 'someMethod']) did not help.

@kamilmysliwiec
Copy link
Member

Please search through some of our old issues on this (this has been discussed several times in the past).

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

No branches or pull requests

3 participants