Page MenuHomePhabricator

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

Authored by ashoat on Nov 27 2023, 12:33 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Dec 21, 11:32 PM
Unknown Object (File)
Thu, Dec 5, 12:59 AM
Unknown Object (File)
Nov 23 2024, 3:32 PM
Unknown Object (File)
Nov 22 2024, 9:17 PM
Unknown Object (File)
Nov 22 2024, 9:12 PM
Unknown Object (File)
Nov 22 2024, 6:01 PM
Unknown Object (File)
Oct 27 2024, 5:33 PM
Unknown Object (File)
Oct 11 2024, 8:03 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 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

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable