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

Typing issue #9

Closed juliusspencer closed 6 years ago

juliusspencer commented 6 years ago

In the index.d.ts there is the following:

declare const _default: ({getItemHeight, getSeparatorHeight, getSectionHeaderHeight, getSectionFooterHeight, listHeaderHeight}: Parameters) => (data: {
    title: string;
    data: any[];
}[], index: number) => {
    length: number | undefined;
    offset: number;
    index: number;
};

In the react-native SectionList is:

getItemLayout?: (
        data: any,
        index: number
    ) => {
        length: number;
        offset: number;
        index: number;
    };

I'm getting a TS error like so:

 Type '{ length: number | undefined; offset: number; index: number; }' is not assignable to type '{ length: number; offset: number; index: number; }'.
            Types of property 'length' are incompatible.
              Type 'number | undefined' is not assignable to type 'number'.
                Type 'undefined' is not assignable to type 'number'.

Would it be possible to change:

length: number | undefined;

to match react-native

 length: number;

I'm not sure if this is possible, it's just that I get a TS error. Or maybe it's how I'm using it. :)

jsoendermann commented 6 years ago

Hi, thanks for your bug report. I just published 2.2.2, let me know if it fixes the problem for you.

juliusspencer commented 6 years ago

Wow thank you so much, that worked!

PS - thank you for making the library and the associated post.