Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript error #14

Open
mbrimmer83 opened this issue Nov 19, 2019 · 8 comments · May be fixed by #16
Open

Typescript error #14

mbrimmer83 opened this issue Nov 19, 2019 · 8 comments · May be fixed by #16

Comments

@mbrimmer83
Copy link

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
Copy link
Owner

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

@mbrimmer83
Copy link
Author

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

@peterkuiper
Copy link

peterkuiper commented Feb 19, 2020

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
Copy link

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
Copy link

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

ping @RaphaelPI

@antoinerousseau antoinerousseau linked a pull request May 6, 2020 that will close this issue
3 tasks
@jpvarbed
Copy link

Are there plans to merge this pr?

@HGCollier
Copy link

Is this being fixed?

@HGCollier
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants