HomePhabricator
Diffusion Comm 303f322ea4f5

[Flow202][native][skip-ci] [13/x] Enable NavigationHelpersContext to…

Description

[Flow202][native][skip-ci] [13/x] Enable NavigationHelpersContext 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 NavigationHelpersContext.Provider inside OverlayNavigator. In that context, in order for the types to match, we need the NavigationHelpersContext.Provider to be able to take a type that is more specific than NavigationHelpers<ParamListBase>.

I initially tried to address this by convincing Flow that the more specific type (OverlayNavigationHelpers<ParamList>) is a subtype of the more general type (NavigationHelpers<ParamListBase>). However, this turned out to be impossible because of a covariance / contravariance issue. Because this type param is used within NavigationHelpersContext.Provider in both "in" and "out" contexts, the type param must match exactly for the subtype relationship to work.

Instead, I concluded that I had to parameterize NavigationHelpersContext.Provider. I started out by looking up the Flow types for React.Context here.

I then implemented an alternate type that matches React.Context, but uses functions with type params in place of React.ComponentType in the Provider and Consumer definitions. With this change, Flow is properly able to match up the types for NavigationHelpersContext.Provider.

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 D9996

Test Plan: Confirm the Flow errors go away

Reviewers: tomek

Reviewed By: tomek

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