Reputation: 2479
I am using a flatlist where flow complains about a missing type of the item object members in the renderItem property:
<FlatList
data={data}
ItemSeparatorComponent={() => <View style={styles.listSeperator} />}
renderItem={({ item }) => (
<WaterConsumptionListItem
timeStamp={item.timeStamp}
amount={item.amount}
datatype={item.dataType}
/>
)}
/>
However I have no idea how to typecheck members of item. The complete error I get is:
Cannot get `item.timeStamp` because property `timeStamp` is missing in `String` [1].Flow(InferError)
Cannot get `item.amount` because property `amount` is missing in `String` [1].Flow(InferError)
Cannot get `item.dataType` because property `dataType` is missing in `String` [1].Flow(InferError)
Upvotes: 1
Views: 2101
Reputation: 2479
Thanks to Alex the solution was to add the type in the data property of the Flatlist like so:
<FlatList data={(data: Array<{ timeStamp: number, amount: number, dataType: string }>)}
Upvotes: 1