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)
Sun, Oct 27, 5:33 PM
Unknown Object (File)
Oct 11 2024, 8:03 PM
Unknown Object (File)
Oct 11 2024, 4:22 PM
Unknown Object (File)
Oct 11 2024, 9:54 AM
Unknown Object (File)
Oct 11 2024, 9:07 AM
Unknown Object (File)
Oct 1 2024, 9:40 PM
Unknown Object (File)
Sep 29 2024, 12:22 AM
Unknown Object (File)
Sep 29 2024, 12:22 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 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
No Lint Coverage
Unit
No Test Coverage
Build Status
Buildable 24437
Build 210153: arc lint + arc unit