使用TypeScript

时间:2019-02-17 06:52:57

标签: reactjs typescript oop generics inheritance

我正在尝试使用比Extending React components in TypeScript

更复杂的基类

这是我的基础课:

export class RootContainer<
  P extends RootContainerProps & RootStateFromProps & RootDispatchFromProps,
  S extends RootContainerState
> extends React.Component<P, S> {
  constructor(props: P) {
    super(props);
    this.state = this.getInitialState();
  }

  getInitialState(): S {
    return { modalIsOpen: false } as S;
  }

然后我尝试扩展如下:

interface MyReservationsContainerProps extends RootContainerProps {
  // Normal component props
}

interface MyReservationsContainerState extends RootContainerState {
  allReservations: Reservation[];
  selectableReservations: Reservation[];
  mode: number;
}

class MyReservationsContainer extends RootContainer<
  MyReservationsContainerProps,
  MyReservationsContainerState
> {

但是我得到这个错误:

  

没有基本的构造函数具有指定数量的类型   arguments.ts(2508)

任何打字稿大师都能帮助我吗?

0 个答案:

没有答案