#Applying decorator to child class decorates the parent class

2 messages · Page 1 of 1 (latest)

cyan vessel
#

I'm trying to use reflection to decorate properties on a child class. I expected it to log out ChildClass but instead logs ParentClass.

import 'reflect-metadata';

export function Searchable(target: Object, property: string) {
  Reflect.defineMetadata('searchable', true, target, property);
  console.log(target);// <--- this prints ParentClass, not ChildClass. why?
}

abstract class ParentClass {
  public id: string;
}

class ChildClass extends ParentClass {
  @Searchable
  public name: string;
}
cyan vessel
#

!helper