如何使用Typescript使用装饰器扩展knockout observable? 示例:使用装饰器进行验证。
interface Person {
firstname:string;
}
class PersonViewModel {
@required
firstname = ko.observable<string>();
constructor (person:Person) {
// put this in an required decorators
// this.firstname.extend({required:true})
this.firstname(person.firstname);
}
}
function required(target, key) {
// ????
// pseudo code extend Person Class variable firstname
// ???firstname.extend({required:true})
}