azangru
azangru

Reputation: 2738

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

Background: in v.0.72.0, Flow deprecated the * type (or, as they call it in the docs, the existential type).

Problem: How do we now describe the type of a React Element (any element; it could be an element rendered out by a React Component, or by a stateless component (simple function), or whatever is rendered when we write html tags in JSX)?

Examples in Try Flow:

Example 1 — typing as Node. This works, but Node is too broad a type, which, besides React elements, includes also strings, numbers, booleans, etc. I would like to narrow the type down.

Example 2 — typing as Element<*>. This also works, but as pointed out above, the * type is now on its way out.

Example 3 — typing as Element<typeof Component>, as per documentation. This doesn’t work. Is there a proper way to make it work?

Upvotes: 3

Views: 936

Answers (1)

Alex Savin
Alex Savin

Reputation: 528

It seems that you can use generics

Upvotes: 1

Related Questions