jsoendermann / rn-section-list-get-item-layout

:black_square_button: Easy getItemLayout props for react-native SectionLists.
https://medium.com/@jsoendermann/sectionlist-and-getitemlayout-2293b0b916fb
Other
221 stars 32 forks source link

Typescript error #14

Open mbrimmer83 opened 4 years ago

mbrimmer83 commented 4 years ago

React-native 59 has getItemLayout typing

getItemLayout?: ((data: SectionListData<any>[] | null, index: number) => {
    length: number;
    offset: number;
    index: number;
}) | undefined

Library type

export type SectionListDataProp = Array<{
  title: string
  data: any[]
}>

Type error

Type '(data: { title: string; data: any[]; }[], index: number) => { length: number; offset: number; index: number; }' is not assignable to type '(data: SectionListData<any>[] | null, index: number) => { length: number; offset: number; index: number; }'.
  Types of parameters 'data' and 'data' are incompatible.
    Type 'SectionListData<any>[] | null' is not assignable to type '{ title: string; data: any[]; }[]'.
      Type 'null' is not assignable to type '{ title: string; data: any[]; }[]'.

It looks like the types for data are no longer compatible.

jsoendermann commented 4 years ago

Hi @mbrimmer83 thanks for reporting this bug. If you have a pull request for me I'm happy to merge.

mbrimmer83 commented 4 years ago

@jsoendermann I am super busy but id love to submit one. I should be able to get one up this weekend. Stay tuned. 😄

peterkuiper commented 4 years ago

This seems to be working for me, although I'm not sure if this is the correct way to fix it:

diff --git a/node_modules/react-native-section-list-get-item-layout/dist/index.d.ts b/node_modules/react-native-section-list-get-item-layout/dist/index.d.ts
index 8f066b8..2b2e5ea 100644
--- a/node_modules/react-native-section-list-get-item-layout/dist/index.d.ts
+++ b/node_modules/react-native-section-list-get-item-layout/dist/index.d.ts
@@ -9,10 +9,10 @@ export interface Parameters {
     getSectionFooterHeight?: (sectionIndex: number) => number;
     listHeaderHeight?: number | (() => number);
 }
-declare const _default: ({ getItemHeight, getSeparatorHeight, getSectionHeaderHeight, getSectionFooterHeight, listHeaderHeight, }: Parameters) => (data: {
-    title: string;
-    data: any[];
-}[], index: number) => {
+declare const _default: ({ getItemHeight, getSeparatorHeight, getSectionHeaderHeight, getSectionFooterHeight, listHeaderHeight, }: Parameters) => (
+  data: any[] | null | undefined,
+  index: number
+) => {
     length: number;
     offset: number;
     index: number;

If anyone could confirm, I'd be more than happy to create a PR.

StagasaurusRex commented 4 years ago

Shouldn't it be something like

declare const _default: ({ getItemHeight, getSeparatorHeight, getSectionHeaderHeight, getSectionFooterHeight, listHeaderHeight, }: Parameters) => (
    data: SectionListData<T>[] | null | undefined,
    index: number,
) => {
    length: number;
    offset: number;
    index: number;
};

I'm new to generics in Typescript, but this seems to work for me.

antoinerousseau commented 4 years ago

Hi guys, I went ahead and opened PR #16 for this 🎉

ping @RaphaelPI

jpvarbed commented 2 years ago

Are there plans to merge this pr?

HGCollier commented 1 year ago

Is this being fixed?

HGCollier commented 1 year ago

For anyone else that comes across this issue, just go into his branch and copy the new code from index.ts into your own file, then use that instead.