react-native-bottom-sheet icon indicating copy to clipboard operation
react-native-bottom-sheet copied to clipboard

[v4] wrong data prop type-def --> BottomSheetFlatList type-def incompatible with union types

Open ThaBrad opened this issue 2 years ago • 2 comments

Bug

Typescript ERROR: index.d.ts(3966, 5): The expected type comes from property 'data' which is declared here on type 'IntrinsicAttributes & Omit<AnimateProps<FlatListProps<A[] | B[]>>, "decelerationRate" | "onScroll" | "scrollEventThrottle"> & ... 5 more ... & RefAttributes<...>'

(property) data: ((readonly (A[] | B[])[] | AnimatedNode<readonly (A[] | B[])[] | null | undefined>) & readonly any[]) | null | undefined

Type 'A[] | B[]' is not assignable to type '((readonly (A[] | B[])[] | AnimatedNode<readonly (A[] | B[])[] | null | undefined>) & readonly any[]) | null | undefined'.
  Type 'A[]' is not assignable to type '((readonly (A[] | B[])[] | AnimatedNode<readonly (A[] | B[])[] | null | undefined>) & readonly any[]) | null | undefined'.
    Type 'A[]' is not assignable to type 'AnimatedNode<readonly (A[] | B[])[] | null | undefined> & readonly any[]'.
      Type 'A[]' is missing the following properties from type 'AnimatedNode<readonly (A[] | B[])[] | null | undefined>': isNativelyInitialized, ' __value'ts(2322)
Screenshot 2022-09-01 at 12 17 47

Environment info

Library Version
@gorhom/bottom-sheet 4.3.2
react-native 0.68.2

Steps To Reproduce

  1. const arrayA: A[] = [0] ; const arrayB: B[] = [1] (==> example just for show)
  2. Have some union-type property const dataResult = someVar ? arrayA : arrayB ( ==> dataResult: A[] | B[])
  3. Assign union-type variable to data property of FlatList (and assign union-type also to renderItem) -->
<FlatList
  data={dataResult}
  renderItem={({ item }: { item: A[] | B[] }): JSX.Element => {
    return (

Describe what you expected to happen:

No typescript error, like the native (react) FlatList type.

Reproducible sample code

code above

ThaBrad avatar Sep 01 '22 10:09 ThaBrad

@ThaBrad: hello! :wave:

This issue is being automatically closed because it does not follow the issue template.

github-actions[bot] avatar Sep 01 '22 10:09 github-actions[bot]

Yes data={dataResult as any} solves this, but why should this libs type differ from the working native implementation?! 🤔

ThaBrad avatar Sep 01 '22 10:09 ThaBrad

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Oct 02 '22 09:10 github-actions[bot]

Should be be simple copy & paste-ing the Typescript types from the native BottomSheet implementation, no?!

ThaBrad avatar Oct 04 '22 14:10 ThaBrad

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Nov 05 '22 09:11 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Nov 10 '22 09:11 github-actions[bot]