HomePhabricator
Diffusion Comm 3d7be75a9d0f

[Flow202][native][skip-ci] [12/x] Enable StackView to parameterize on invocation

Description

[Flow202][native][skip-ci] [12/x] Enable StackView to parameterize on invocation

Summary:
One of the quirks of Flow is that the only way to type a React component in a way where the types are parameterized on invocation is to type it as a function.

In our codebase, we render StackView inside a couple custom navigators. In those contexts, in order for the types to match, we need the StackView to be able to take a type that is more specific than StackNavigationHelpers<>.

I initially tried to address this by convincing Flow that the more specific types (ChatNavigationHelpers<> and RootNavigationHelpers<>) are subtypes of the more general type (StackNavigationHelpers<>). However, this turned out to be impossible because of a covariance / contravariance issue. Because StackNavigationHelpers's type param is used in both "in" and "out" contexts, that type param must match exactly for the subtype relationship to work.

Instead, I concluded that I had to parameterize StackView. I implemented an alternate type that matches the existing one, but uses a function with type params in place of React.ComponentType. With this change, Flow is properly able to match up the types for `StackView.

NOTE: CI will fail on this diff. I considered the possibility of fixing Flow errors BEFORE upgrading Flow, but it wasn't possible... in some cases, the fixes to support the new version of Flow caused errors in the old version. I could have hidden these type errors with $FlowFixMe lines and then later revert those, but that seemed like too much busy work.

Depends on D9995

Test Plan: Confirm the Flow errors go away

Reviewers: tomek

Reviewed By: tomek

Differential Revision: https://phab.comm.dev/D9996

Details