score:6

Accepted answer

This should work:

import * as React from "react";

// In a more realistic example, there would be a more interesting relationship
// between the props types of the wrapped and resulting components.    
function HOC(): <P>(Component: React.ComponentType<P>) => React.ComponentClass<{}> {
    return function<P>(Component: React.ComponentType<P>): React.ComponentClass<{}> {
        return class Bar extends React.Component<{}> {}
    }
}

class Foo extends React.Component<{x: string},{}> {}
const Bar = HOC()(Foo);
// Get the instance type corresponding to the `Bar` constructor function,
// as you would have if you had just written `class Bar`.
type Bar = InstanceType<typeof Bar>;

class Test extends React.Component {
    private ref: React.RefObject<Bar> = React.createRef<Bar>();

    render(): any {
        return (
            <React.Fragment>
              <Bar
                ref={this.ref}
              />
            </React.Fragment>
        );
    }
}

Related Query

More Query from same tag