leecade / react-native-swiper

The best Swiper component for React Native.
MIT License
10.42k stars 2.34k forks source link

Typescript: Props should (maybe) extend ScrollViewProps #834

Open mmarvick opened 6 years ago

mmarvick commented 6 years ago

Which OS ?

N/A

Version

Which versions are you using:

Expected behaviour

I should be able to add most ScrollViewProps (e.g. keyboardShouldPersistTaps={'handled'}), and TypeScript shouldn't complain.

Actual behaviour

TypeScript doesn't know that I can use other scrollview props.

Misc

With some exception of overwritten props by the library, almost all props that can be set on ScrollView can be set on swiper: https://github.com/leecade/react-native-swiper/blob/master/src/index.js#L626

It'd be great if we could just extend from ScrollViewProps. Because some properties like ScrollView's style are getting set to other things like Swiper's scrollViewStyle, extending the typing and exposing a style property may be misleading. I'm not sure if you can "extend an interface except for these ___ props", but if you can that seems like an ideal solution.

At the very least.. I'd love to get keyboardShouldPersistTaps added to the definition :) But there's probably others too that could be brought over.

mmarvick commented 6 years ago

It looks like you can use TypeScript's Exclude to remove props from a type. https://stackoverflow.com/a/49662505/3081611

So it'd be possible to exclude a few things from ScrollViewProps that can't really be set on Swiper (e.g. style), and then have SwiperProps extend from that.

GutteApps commented 5 years ago

+1 for adding keyboardShouldPersistTaps

kyle-ssg commented 4 years ago

This can be closed. Adding keyboardShouldPersistTaps="handled" successfully added the prop.