-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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 DatePickerAndroid error when passing "minDate: null" #21338
Fix DatePickerAndroid error when passing "minDate: null" #21338
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eslint
found some issues. You may run yarn prettier
or npm run prettier
to fix these.
@@ -18,7 +18,7 @@ const DatePickerModule = require('NativeModules').DatePickerAndroid; | |||
function _toMillis(options: Object, key: string) { | |||
const dateVal = options[key]; | |||
// Is it a Date object? | |||
if (typeof dateVal === 'object' && typeof dateVal.getMonth === 'function') { | |||
if (dateVal != null && typeof dateVal == 'object' && typeof dateVal.getMonth === 'function') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prettier/prettier: Replace dateVal·!=·null·&&·typeof·dateVal·==·'object'·&&·typeof·dateVal.getMonth·===·'function'
with ⏎····dateVal·!=·null·&&⏎····typeof·dateVal·==·'object'·&&⏎····typeof·dateVal.getMonth·===·'function'⏎··
@@ -18,7 +18,7 @@ const DatePickerModule = require('NativeModules').DatePickerAndroid; | |||
function _toMillis(options: Object, key: string) { | |||
const dateVal = options[key]; | |||
// Is it a Date object? | |||
if (typeof dateVal === 'object' && typeof dateVal.getMonth === 'function') { | |||
if (dateVal != null && typeof dateVal == 'object' && typeof dateVal.getMonth === 'function') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eqeqeq: Expected '===' and instead saw '=='.
Generated by 🚫 dangerJS |
Thanks for contributing! This file really looks like it needs to be flow typed. This change just feels like a small patch that might not completely handle all the cases of things not being typesafe. Would you be willing to take a stab at flow typing this file to ensure we are properly handling all of the different edge cases of |
@TheSavior I'll do some flow-typing within the two next days as soon as I have a quiet moment. Just two questions about static async open(options: Object): Promise<Object> {
const optionsMs = options;
if (optionsMs) {
_toMillis(options, 'date');
_toMillis(options, 'minDate');
_toMillis(options, 'maxDate');
}
return DatePickerModule.open(options);
} 1 - Why doing this: 2 - Why mutating the |
The answer to both of your questions are "this is legacy code, I wouldn't want it written this way today". Good news! You can make it better! :D Fortunately, if you flow type |
Thanks for fixing this, @MaxInMoon! :) Since this is a pretty simple change, I think we can merge this PR as is. But as @TheSavior said, it'd be better if this file were flow-typed. The error you caught at run-time could have easily been caught at compile-time. Would you like to launch another PR? Feel free to refactor as you see fit. Edit: Whoops. @MaxInMoon, it looks like I can't merge this because you haven't signed the CLA. |
I agree with @TheSavior and @RSNara that this file should be flow typed instead of adding more runtime checks. Since there haven't been any updates in more than three months I'm gonna close this PR. I'm happy to reopen or land a new PR that adds Flow types to this module. Thank you for bringing this issue to our attention! |
It avoids an error when passing an options object with minDate: null. (see #21253)
Inspired by isObjectLike from Loadash.
Fixes #21253
@RSNara reviewer?
Test Plan:
This jsbin allow to test the old and the new
_toMillis
function.You can observe that
_toMillis
doesn't throw error (fixed) and that if you decomment the_toMillis_before_pr
call, it will generate an error as before.Release Notes:
[ANDROID] [BUGFIX] [DatePickerAndroid] fix error when passing
minDate: null
inoptions