FlatList doesn't properly infer types
See original GitHub issueEx.
This works:
import { FlatList } from "react-native";
const CreateOptions = [
{
id: "1",
title: "Supplement",
background: {
uri:
"https://images.unsplash.com/photo-1565071783280-719b01b29912?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1650&q=80",
},
},
];
<FlatList
showsHorizontalScrollIndicator={false}
horizontal
data={CreateOptions}
renderItem={({ item, index }) => (
<Pressable sx={{ m: "md" }}>
<Image
sx={{ height: 180, width: 120, borderRadius: "base" }}
source={item.background}
/>
</Pressable>
)}
keyExtractor={(item) => item.title}
/>
This produces the following, for the object item typescript errors with Object is of type 'unknown':
import { FlatList } from "dripsy";
const CreateOptions = [
{
id: "1",
title: "Supplement",
background: {
uri:
"https://images.unsplash.com/photo-1565071783280-719b01b29912?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1650&q=80",
},
},
];
<FlatList
showsHorizontalScrollIndicator={false}
horizontal
data={CreateOptions}
renderItem={({ item, index }) => (
<Pressable sx={{ m: "md" }}>
<Image
sx={{ height: 180, width: 120, borderRadius: "base" }}
source={item.background}
/>
</Pressable>
)}
keyExtractor={(item) => item.title}
/>
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
TypeScript React Native Flatlist: How to give renderItem the ...
Show activity on this post. I'm building a React Native app with TypeScript. renderItem complains that the destructured item implicitly has an ...
Read more >A deep dive into React Native FlatList - LogRocket Blog
FlatList is a React Native component that allows you to render lists with zero hassle and minimal code. Learn how to customize FlatList....
Read more >FlatList - React Native
A performant interface for rendering basic, flat lists, supporting the most handy features:
Read more >API | React Native Testing Library - Open Source
The Props type is determined by the type passed to or inferred by the renderHook call. unmount . A function to unmount the...
Read more >Flutter for React Native developers
In JavaScript, variables cannot be typed. In Dart, variables must either be explicitly typed or the type system must infer the proper type...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I know this isn’t ideal, but this does do it for me as a temporary work-around:
I haven’t found a good solution to this. It’s frustrating, but I don’t know the alternative.
https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref/58473012
It seems like
forwardRefdoesn’t let us forwardreftypes for generics. So either we use the generic, or thereftype. I’m open to a solution, but I’m going to close it since I can’t find one that doesn’t involve writing types directly.So if you’re coming to this issue, please see https://github.com/nandorojo/dripsy/issues/58#issuecomment-750494694