0
votes

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)
1
I don't know flow, but it looks like it is inferring that item has type string. Can you give item a type explicitly in the anonymous function? - danh
that is exaclty what I do not know :) - zlZimon
Can you add a type for data like this: <FlatList data={(data: Array<{ timeStamp: number, amount: number, dataType: string }>)}? - Alex Savin
What are the types of FlatList and item and data? Not really enough information here. - Lyle Underwood

1 Answers

0
votes

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 }>)}