beforesemicolon / flatlist-react

A helpful utility component to handle lists in react like a champ
MIT License
95 stars 17 forks source link

TypeScript: type `renderItem` function to an element of `list` prop #94

Closed habovh closed 1 year ago

habovh commented 1 year ago

Is your feature request related to a problem? Please describe. The first parameter of the renderItem function is being typed as any and is therefore not type-safe.

Describe the solution you'd like Ideally, <FlatList /> should infer the type from the list prop. React Native's <FlatList /> component supports this.

Describe alternatives you've considered The current workaround is to manually set the type when defining the function. It's less than ideal because it's a manual step and it's not helping keep the code lean.

ECorreia45 commented 1 year ago

@habovh which version are you using?

Can you share a code snippet or screenshot of what you are seeing?

habovh commented 1 year ago

You can see it in action here. Version is 1.5.3.

Hovering the first parameter gives an implicit any type error: Screenshot 2022-11-18 at 09 07 20

And looking at flatListProps.d.ts, you can see there's no generics that could carry types between list and renderItem: Screenshot 2022-11-18 at 09 07 59

habovh commented 1 year ago

For comparison, here is the same component using React Native's flatlist.

Item type is inferred properly: Screenshot 2022-11-18 at 09 23 52

And here's what the exported types look like (I moved code around to make this screenshot smaller): Screenshot 2022-11-18 at 09 24 39

ECorreia45 commented 1 year ago

Thanks. Its being worked on

ECorreia45 commented 1 year ago

fix available on next npm i flatlist-react@next https://www.npmjs.com/package/flatlist-react/v/1.5.5-next