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

fix (types): onDateChangeonChange #612

Merged
merged 3 commits into from Oct 25, 2021
Merged

Conversation

mmazzarolo
Copy link
Owner

@mmazzarolo mmazzarolo commented Oct 23, 2021

Our typedefs were exposing onDateChange (wrong signature) instead of onChange (correct signature). We replaced the onDateChange type with onChange.

Fixes #611

BREAKING CHANGE: Our typedefs were exposing `onDateChange` (wrong signature) instead of `onChange` (correct signature). We replaced the `onDateChange` type with `onChange`.
*/
onDateChange?(newDate: Date): void;
onChange?(newDate: Date): void;
Copy link
Contributor

@punksta punksta Oct 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be confusing.

The final type of your component props is defined as (214 line)

export type ReactNativeModalDateTimePickerProps = DateTimePickerProps &
  Omit<IOSNativeProps, "value" | "mode"> &
  Omit<AndroidNativeProps, "value" | "mode">;

IOSNativeProps and AndroidNativeProps are coming from @react-native-community/datetimepicker library. and
onChange?: (event: Event, date?: Date) => void; presents in both IOSNativeProps and AndroidNativeProps.

So the final type of the onChange will be

 ((date: Date) => void) & ((event: Event, date: Date) => void)

Are you sure you want to change types of the original library?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — I added onChange to the omitted types. I'm not sure if that makes it less confusing to you, but we're already overriding other props (e.g., mode, value) with the ones we support.
As long as the prop is documented in the README.md, I think we should be fine (maybe we can update the README.md mentioning that we support only the non-overridden community-picker prop — but this hasn't been a problem so far).
...unless you think we should expose the event as well. I would prefer to not add additional complexity to the API we're exposing unless is needed, and I don't think the event has any meaningful info that couldn't already be obtained in other ways (but let me know if I'm missing something).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for changing it.

Latest suggestion solves my problem.

I am not sure how meaningful event is. I cant' find use case for me, but some people are using it in the datetimepicker library: react-native-datetimepicker/datetimepicker#359

@mmazzarolo mmazzarolo merged commit 93cddd4 into master Oct 25, 2021
@mmazzarolo mmazzarolo deleted the mmazzarolo-patch-1 branch October 25, 2021 09:00
@mmazzarolo
Copy link
Owner Author

Thanks again @punksta for raising the issue and reviewing the PR! 🙌

github-actions bot pushed a commit that referenced this pull request Oct 25, 2021
# [13.0.0](v12.0.0...v13.0.0) (2021-10-25)

* fix (types): `onDateChange` → `onChange` (#612) ([93cddd4](93cddd4)), closes [#612](#612)

### BREAKING CHANGES

* Our typedefs were exposing `onDateChange` (wrong signature) instead of `onChange` (correct signature). We replaced the `onDateChange` type with `onChange`.
@github-actions
Copy link

🎉 This PR is included in version 13.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

inconsistancy between onDateChange, onChange in ts and js.
2 participants