-
Notifications
You must be signed in to change notification settings - Fork 185
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
Decorated class inheritance issue #62
Comments
What does |
I am also seeing this. Although, I am using decorators on constructor parameters rather than as class properties. I imagine the code path is roughly the same though. class AbstractComponent {
constructor (@Inject('form') @Host() formController: IFormController) { ... }
}
class ComponentA extends AbstractComponent { ... } // no constructor
class ComponentB {
constructor (@Inject('form') @Host() formController: IFormController,
@Inject('$http') $http: IHttpService) { ... }
} Angular will actually throw an error here,
It looks like it's registering all metadata against the parent class and not the child classes. Using ng-metadata to wire everything up behind the scenes. |
@igorzg does angular change something with Reflect? Because I get this issue when not running it through angular (though angular is present...):
EDIT: solved by being more defensive (ie: this comment, suggested above |
I'm facing the same issue. I have classes that extend from the same parent class and the metadata is stored on the parent and not the individual classes (or so it seems). Unfortunately I have to admit that I don't understand the comments above. Is there a way to be "defensive" so that the metadata is only stored on the child class (whilst remaining that of the parent)? Update: A theory I had was that the amount of alcohol consumed would affect my ability to both process the information and apply it properly. Further research has proven this theory right. I shall now slowly move backwards into the shadows and bow my head in shame. |
Is there any update on this, I'm facing the exact same problem. |
Same here. import 'reflect-metadata';
const Searchable = (target: Object, property: string) => {
Reflect.defineMetadata('searchable', true, target, property);
console.log(target);// <--- this prints ParentClass, not ChildClass
}
abstract class ParentClass {
public id: string;
}
class ChildClass extends ParentClass {
@Searchable
public name: string;
} |
Hi All, you can use https://typeix.com/packages/metadata/ which solves problem for you. |
@igorzg I'm not sure that adding another npm package is really the solution here. More broadly, however - the solution ended up being: - console.log(target)
+ console.log(target.constructor) |
Facing this same issue in version 0.2.1. If the decorator exists in only the child classes it works great. But as soon as the base class has a the same decorator it references the base class instead of the passed in target
|
When multiple instances extends from the same base class that has decorated properties. Children decorators 'pollutes' parent metadata. They were also attached to parent prototype.
Example:
following decorators use
reflect-metadata
to 'define' and 'get' metadata.This will result
class B
has three metadata,prop
,propA
andpropB
The text was updated successfully, but these errors were encountered: