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)
Mon, May 6, 3:25 PM
Unknown Object (File)
Mon, May 6, 3:25 PM
Unknown Object (File)
Mon, May 6, 3:24 PM
Unknown Object (File)
Mon, May 6, 2:53 PM
Unknown Object (File)
Wed, May 1, 10:37 PM
Unknown Object (File)
Wed, May 1, 3:41 PM
Unknown Object (File)
Mon, Apr 22, 3:36 PM
Unknown Object (File)
Tue, Apr 16, 5:32 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
Lint Not Applicable
Unit
Tests Not Applicable