We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
This feature is related to my issue that closed without any solution.
Previous issue: #471
We can create inheritMethods function like this:
inheritMethods
export function inheritMethods( parentClass: Type<any>, targetClass: Function, isPropertyInherited?: (key: string) => boolean, ) { Object.getOwnPropertyNames(parentClass.prototype) .filter( (propertyName) => !isPropertyInherited || isPropertyInherited(propertyName), ) .forEach((name) => { Object.defineProperty( targetClass.prototype, name, Object.getOwnPropertyDescriptor(parentClass.prototype, name) || Object.create(null), ); }); }
and edit omit-type.helper.ts like this:
omit-type.helper.ts
import { Type } from '@nestjs/common'; import { MappedType } from './mapped-type.interface'; import { inheritPropertyInitializers, inheritTransformationMetadata, inheritValidationMetadata, inheritMethods, } from './type-helpers.utils'; export function OmitType<T, K extends keyof T>( classRef: Type<T>, keys: readonly K[], ): MappedType<Omit<T, typeof keys[number]>> { const isInheritedPredicate = (propertyKey: string) => !keys.includes(propertyKey as K); abstract class OmitClassType { constructor() { inheritPropertyInitializers(this, classRef, isInheritedPredicate); } } inheritValidationMetadata(classRef, OmitClassType, isInheritedPredicate); inheritTransformationMetadata(classRef, OmitClassType, isInheritedPredicate); inheritMethods(classRef, OmitClassType, isInheritedPredicate); return OmitClassType as MappedType<Omit<T, typeof keys[number]>>; }
and add inheritMethods(classRef, OmitClassType, isInheritedPredicate); too all type helpers.
inheritMethods(classRef, OmitClassType, isInheritedPredicate);
We just need to add this function in type-helpers.utils.ts
type-helpers.utils.ts
and use it in all type-helpers.
We can now inherit methods using type helpers
The text was updated successfully, but these errors were encountered:
This has been discussed several times in the past and we don't plan to add such a feature to this package.
Sorry, something went wrong.
No branches or pull requests
Is there an existing issue that is already proposing this?
Is your feature request related to a problem? Please describe it
This feature is related to my issue that closed without any solution.
Previous issue:
#471
Describe the solution you'd like
We can create
inheritMethods
function like this:and edit
omit-type.helper.ts
like this:and add
inheritMethods(classRef, OmitClassType, isInheritedPredicate);
too all type helpers.Teachability, documentation, adoption, migration strategy
We just need to add this function in
type-helpers.utils.ts
and use it in all type-helpers.
What is the motivation / use case for changing the behavior?
We can now inherit methods using type helpers
The text was updated successfully, but these errors were encountered: