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
F3532275: D9997.id33641.diff
Wed, Dec 25, 8:59 AM
F3531721: D9997.id33880.diff
Wed, Dec 25, 7:54 AM
F3529711: D9997.diff
Tue, Dec 24, 8:48 PM
Unknown Object (File)
Sun, Dec 15, 3:48 PM
Unknown Object (File)
Sat, Dec 14, 9:22 PM
Unknown Object (File)
Sat, Dec 14, 9:16 PM
Unknown Object (File)
Nov 23 2024, 1:50 PM
Unknown Object (File)
Oct 27 2024, 5:33 PM
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
No Lint Coverage
Unit
No Test Coverage
Build Status
Buildable 24438
Build 210154: arc lint + arc unit