Flow:不推荐使用存在类型,如何键入 React 元素?

Flow: with existential type deprecated, how to type a React element?

背景: in v.0.72.0,Flow deprecated the * type (or, as they call it in the docs,存在类型)。

问题:我们现在如何描述 React 元素的类型(任何元素;它可以是由 React 组件呈现的元素,或由无状态组件呈现的元素(简单函数),或者当我们在 JSX 中编写 html 标签时渲染的任何东西)?

尝试流程中的示例:

Example 1 — 键入 Node。这行得通,但是 Node 的类型太广泛了,除了 React 元素之外,它还包括字符串、数字、布尔值等。我想缩小类型范围。

Example 2 — 键入 Element<*>。这也有效,但如上所述,* 类型现在即将淘汰。

Example 3 — typing as Element<typeof Component>, as per documentation。这是行不通的。有没有合适的方法让它发挥作用?

看来你can使用泛型