How to implement a typescript decorator? is a good example about how to use decorator in typescript.
Considering the below case,
class MyClass {
@enumerable(false)
get prop() {
return true;
}
@property({required: true}) //here pass constant is no issue
public startDateString:string;
@property({afterDate: this.startDateString}) //how to pass startDateString here?
public endDateString:string;
}
function enumerable(isEnumerable: boolean) {
return (target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>) => {
descriptor.enumerable = isEnumerable;
return descriptor;
};
}
I tried everything but it seems I have no way to pass startDateString into decorator argument. startDateString could be a variable, a function and a reference.
startDateStringto the decorator applied toendDateString, but what are you planning to do with it in the decorator? Depending on circumstances, it is possible to get an instance member through a decorator.