How to use Flow with React.createRef()?

Looking at the flow type definition for React.createRef():

declare export function createRef<ElementType: React$ElementType>(
): {current: null | React$ElementRef<ElementType>};

I was able to do something like this:

/* @flow */
import * as React from 'react';

export class TestComponent extends React.Component<{}> {
  myRef: { current: null | HTMLDivElement }

  constructor(props: any) {
    super(props)
    this.myRef = React.createRef()
  }

  render() {
    return (
      <div ref={this.myRef} />
    )
  }
}

There is a related github issue.

If it's not fixed yet you can type it yourself:

type RefObject = {|
  current: any,
|};

This is how it is typed internally in react library type definitions.