如何实现打字稿装饰器?关于如何在打字稿中使用装饰器是一个很好的例子.
考虑到以下情况,
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;
};
}
Run Code Online (Sandbox Code Playgroud)
我尝试了一切,但似乎我无法startDateString进入装饰器参数.startDateString可以是变量,函数和引用.