Page MenuHomePhabricator

[Flow202][native][skip-ci] [13/x] Enable NavigationHelpersContext to parameterize on invocation
ClosedPublic

Authored by ashoat on Nov 27 2023, 12:33 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Oct 27, 5:33 PM
Unknown Object (File)
Sep 29 2024, 12:22 AM
Unknown Object (File)
Sep 29 2024, 12:22 AM
Unknown Object (File)
Sep 29 2024, 12:21 AM
Unknown Object (File)
Sep 29 2024, 12:10 AM
Unknown Object (File)
Aug 28 2024, 8:05 AM
Unknown Object (File)
Aug 28 2024, 6:29 AM
Unknown Object (File)
Aug 28 2024, 6:29 AM
Subscribers
None

Details

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

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable