相关疑难解决方法(0)

如何将实例变量传递给typescript decorator参数?

如何实现打字稿装饰器?关于如何在打字稿中使用装饰器是一个很好的例子.

考虑到以下情况,

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可以是变量,函数和引用.

decorator typescript

15
推荐指数
1
解决办法
2835
查看次数

标签 统计

decorator ×1

typescript ×1