Reactjs 如何将类型设置为ref对象,该对象可以分配给具有相同根类的所有继承类

Reactjs 如何将类型设置为ref对象,该对象可以分配给具有相同根类的所有继承类,reactjs,typescript-typings,typescript-generics,Reactjs,Typescript Typings,Typescript Generics,我的继承层次结构如下所示: abstract class MyClass { protected componentRef: React.RefObject</* This is where I'm stuck */> = React.createRef(); public render() { const Component = flag ? B : D; return ( <Component

我的继承层次结构如下所示:

abstract class MyClass {

    protected componentRef: React.RefObject</* This is where I'm stuck */> = React.createRef();

    public render() {
        const Component = flag ? B : D;
        return (
          <Component
            {...props}
            ref={this.componentRef}
          />
        );
    }
}

在另一个组件(称之为MyClass)中,我使用组件
B
D
(或任何具体类
E、F、G、H
),如下所示:

abstract class MyClass {

    protected componentRef: React.RefObject</* This is where I'm stuck */> = React.createRef();

    public render() {
        const Component = flag ? B : D;
        return (
          <Component
            {...props}
            ref={this.componentRef}
          />
        );
    }
}
但是没有成功。老实说,我不熟悉类型脚本类型定义方案。 另外,我不喜欢下面的解决方案

abstract class MyClass<ComponentType extends A> {
  protected componentRef: React.RefObject<ComponentType> = React.createRef();
}
抽象类MyClass{
受保护的componentRef:React.ReObject=React.createRef();
}
并将类型设置为
any

有没有可能存在其他类似于我尝试的解决方案?(如使用
type
关键字定义泛型类型)