在使用Typescript的React中,我们可以这样做:

constructor(props: Props) {
    super(props);
    this.state = {
      teams: []
    };
  }

要明确地让typescript编译器知道将哪些props传递给构造函数生命周期方法 . 但是我们已经让组件知道类声明中组件中可用的哪些道具

extends Component<Props, State> {

因此,在所有生命周期方法中再次指定它似乎是多余的 . 组件类型文件似乎支持这个(@ types / react v.16.4.16):

class Component<P, S> {
    constructor(props: Readonly<P>);

所以问题是为什么这不起作用? (打字稿对2.9.2)

enter image description here