Typescript扩展了任何类型

时间:2018-01-03 11:11:34

标签: javascript typescript types formatting

这是装饰器功能:

const func = className => {
  let instance = new className();
  extendObservable(instance, instance.observables);
  return instance;
};

export default func;

这是班级:

@func
class testClass {
  observables = {
    name: "",
    fname: "",
    age: 0,
  };
  .
  .
  .
  .
  someMethod() {
    let a = this.name  // <<<<< I'm getting property name does
                       //       not exist on type testClass
  }
}

如何在不复制所有可观察量的情况下删除此错误&#39;像这样的类的属性:

 name: string
 fname: string
 age: number
 observables = {
    name: "",
    fname: "",
    age: 0,
  };

0 个答案:

没有答案