Fixup fbsource for $ArrayLike FlatList data (#37314)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/37314

Turns out we never transitioned fbsource to an API change we made for FlatList, due to mismatched `.js` and `.js.flow` files.

Inside of RN, `$ArrayLike` in Flow, unlike `ArrayLike` in TypeScript, treats `length` as writable. So we wrap that in `$ReadOnly`. Another option might be to inline our own version, since it is not the only [case where they differ](https://fb.workplace.com/groups/flow/permalink/24328911383397481/).

In product code, the changes end up impacting:
1. `getItemLayout` is no longer typed to receive a mutable array. I changed all of the incompatible explicit type parameters from `Array<ItemT>` to `Iterable<ItemT>`.
2. Flow has a harder time inferring destructured `data` in examples that were passing `any` to FlatList, so I needed to give some type hints where `data` was previously untyped
3. Replace some `$FlowFixMe[incompatible-type]` with `$FlowFixMe[incompatible-type-arg]`

Changelog: [Internal]

Reviewed By: lunaleaps

Differential Revision: D45665199

fbshipit-source-id: 59aa908e277a27f7ca88acb48de493d2782517a9
This commit is contained in:
Nick Gerleman
2023-05-08 15:49:50 -07:00
committed by Facebook GitHub Bot
parent 2029688630
commit ea12c4c3d0
3 changed files with 5 additions and 5 deletions
@@ -231,7 +231,7 @@ class NativeCxxModuleExampleExample extends React.Component<{||}, State> {
</TouchableOpacity>
</View>
<FlatList
// $FlowFixMe[incompatible-type]
// $FlowFixMe[incompatible-type-arg]
data={Object.keys(this._tests)}
keyExtractor={item => item}
renderItem={({item}: {item: Examples, ...}) => (