peacechen / react-native-modal-selector

A cross-platform (iOS / Android), selector/picker component for React Native that is highly customizable and supports sections.
MIT License
369 stars 129 forks source link

ModalSelector renderItem typing error #168

Closed scousino closed 3 years ago

scousino commented 3 years ago

Somewhere between versions 2.0.2 and 2.0.7 the typings for the props on ModalSelector were changed to include FlatListProps. Since that change, TypeScript now throws an error unless you provide the renderItem property that is required for a FlatList. However, I know that is wrong, because this package already takes care of providing a renderItem implementation in its code.

I believe the solution is to utilize Pick, Omit, Exclude from TypeScript in some way, but I'm not familiar with exactly how

andkom commented 3 years ago

same for me

cesarve77 commented 3 years ago

Same

GoreckiK commented 3 years ago

same here

joseclaudiojr commented 3 years ago

Adding PropTypes.array to line 32 solves the problem: style: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),

peacechen commented 3 years ago

@joseclaudiojr Please submit a PR

scousino commented 3 years ago

Adding PropTypes.array to line 32 solves the problem: style: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),

This in no way fixes the problem mentioned in this issue. Your fix isn't even a typescript change.

joseclaudiojr commented 3 years ago

Adding PropTypes.array to line 32 solves the problem: style: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),

This in no way fixes the problem mentioned in this issue. Your fix isn't even a typescript change.

This repo uses prop-types to document the intended types of properties passed to components. (https://www.npmjs.com/package/prop-types)

scousino commented 3 years ago

Adding PropTypes.array to line 32 solves the problem: style: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),

This in no way fixes the problem mentioned in this issue. Your fix isn't even a typescript change.

This repo uses prop-types to document the intended types of properties passed to components. (https://www.npmjs.com/package/prop-types)

This has nothing to do with prop types and the style prop type has nothing to do with renderItem.

I am describing a TypeScript error. I suggest learning the difference between the two before submitting a PR for packages

joseclaudiojr commented 3 years ago

Adding PropTypes.array to line 32 solves the problem: style: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),

This in no way fixes the problem mentioned in this issue. Your fix isn't even a typescript change.

This repo uses prop-types to document the intended types of properties passed to components. (https://www.npmjs.com/package/prop-types)

This has nothing to do with prop types and the style prop type has nothing to do with renderItem.

I am describing a TypeScript error. I suggest learning the difference between the two before submitting a PR for packages

Well, it looks like you didn't really check the solution. Anyway, i was having a typescript issue and that worked for me. Good luck in finding your answer, looks like you gonna need it....

scousino commented 3 years ago

Again PropTypes are not for TypeScript, literally look it up. PropTypes provide typing for JAVASCRIPT. Type Script is only affected by changes to type definition files. In this case index.d.ts. Again your change is still not even related to the issue you commented on. Please try and follow standard issue guidelines. Open a separate issue if you're having problems with the PropTypes

mikaello commented 3 years ago

Thanks for your interest in this issue, @scousino and @joseclaudiojr :-) I think I found a fix: https://github.com/peacechen/react-native-modal-selector/commit/539673ac7ebfd1360fc3abaf0c0fda9be5fb6c5e

Could you test default branch and confirm if this works for you or not?

You could test default branch (master) by installing like this: npm install peacechen/react-native-modal-selector.

andkom commented 3 years ago

please also add methods

-export default class ModalSelector<TOption = IOption> extends React.Component<IModalSelectorProps<TOption> & FlatListProps<any>, any> {}
+export default class ModalSelector<TOption = IOption> extends React.Component<IModalSelectorProps<TOption> & Omit<FlatListProps<any>, any>, 'renderItem'> {
+  open(): void;
+  close(): void;
+  getSelectedItem(): string | undefined;
+}
mikaello commented 3 years ago

They are added in another PR: https://github.com/peacechen/react-native-modal-selector/pull/161 (or at least open and getSelectedItem), I will merge that when this issue is resolved.

mikaello commented 3 years ago

Fixed in v2.0.9