如何在课堂上实现动态属性

时间:2019-06-13 17:31:53

标签: flowtype

流量获取错误Cannot assignto this [key] because an index signature declaring the expected key / value type is missing in Dict [1]. 这样可以实现这样的代码吗?

class Dict {
  constructor(props: Object) {
    Object.entries(props).forEach(([key, value]) => {
      this[key] = value;
    });
  }
}

class Int extends Dict {
  value: number;
  constructor({ value }) {
    super({ name: 'int', value });
  }
}

const int = new Int({ value: 1 });

const type: number = int.value;

0 个答案:

没有答案