From 60f3b53cefe7d728b1f37bb70a1039c243b5b30f Mon Sep 17 00:00:00 2001 From: nd-02110114 Date: Wed, 26 Dec 2018 12:00:56 -0800 Subject: [PATCH] Flow strict in DatePickerAndroid.android.js, DatePickerAndroid.ios.js (#22106) Summary: Related to #22100 Turn Flow strict mode on for DatePickerAndroid - [x] npm run prettier - [ ] npm run flow-check-ios - [ ] npm run flow-check-android This error was happend #22101 #22048 [GENERAL] [ENHANCEMENT] [Components/DatePickerAndroid/DatePickerAndroid.android.js] - Flow strict mode [GENERAL] [ENHANCEMENT] [Components/DatePickerAndroid/DatePickerAndroid.ios.js] - Flow strict mode Pull Request resolved: https://github.com/facebook/react-native/pull/22106 Reviewed By: TheSavior Differential Revision: D12919276 Pulled By: RSNara fbshipit-source-id: 79672b2894435ca3c9988fefee3685700a8d8936 --- .../DatePickerAndroid.android.js | 35 ++++++++++++++----- .../DatePickerAndroid.ios.js | 11 ++++-- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/Libraries/Components/DatePickerAndroid/DatePickerAndroid.android.js b/Libraries/Components/DatePickerAndroid/DatePickerAndroid.android.js index 734a59abf72cf4..5f888502ef14b3 100644 --- a/Libraries/Components/DatePickerAndroid/DatePickerAndroid.android.js +++ b/Libraries/Components/DatePickerAndroid/DatePickerAndroid.android.js @@ -5,17 +5,38 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict-local */ 'use strict'; const DatePickerModule = require('NativeModules').DatePickerAndroid; +type Options = $ReadOnly<{| + date?: ?(Date | number), + minDate?: ?(Date | number), + maxDate?: ?(Date | number), + mode?: ?('calender' | 'spinner' | 'default'), +|}>; + +type DatePickerOpenAction = + | {| + action: 'dateSetAction', + year: number, + month: number, + day: number, + |} + | {| + action: 'dismissedAction', + year: typeof undefined, + month: typeof undefined, + day: typeof undefined, + |}; + /** * Convert a Date to a timestamp. */ -function _toMillis(options: Object, key: string) { +function _toMillis(options: Options, key: string) { const dateVal = options[key]; // Is it a Date object? if (typeof dateVal === 'object' && typeof dateVal.getMonth === 'function') { @@ -65,7 +86,7 @@ class DatePickerAndroid { * Note the native date picker dialog has some UI glitches on Android 4 and lower * when using the `minDate` and `maxDate` options. */ - static async open(options: Object): Promise { + static async open(options: Options): Promise { const optionsMs = options; if (optionsMs) { _toMillis(options, 'date'); @@ -78,15 +99,11 @@ class DatePickerAndroid { /** * A date has been selected. */ - static get dateSetAction() { - return 'dateSetAction'; - } + static dateSetAction = 'dateSetAction'; /** * The dialog has been dismissed. */ - static get dismissedAction() { - return 'dismissedAction'; - } + static dismissedAction = 'dismissedAction'; } module.exports = DatePickerAndroid; diff --git a/Libraries/Components/DatePickerAndroid/DatePickerAndroid.ios.js b/Libraries/Components/DatePickerAndroid/DatePickerAndroid.ios.js index bb6442b5262c79..01c45302fcdf25 100644 --- a/Libraries/Components/DatePickerAndroid/DatePickerAndroid.ios.js +++ b/Libraries/Components/DatePickerAndroid/DatePickerAndroid.ios.js @@ -5,13 +5,20 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict-local */ 'use strict'; +type Options = $ReadOnly<{| + date?: ?(Date | number), + minDate?: ?(Date | number), + maxDate?: ?(Date | number), + mode?: ?('calender' | 'spinner' | 'default'), +|}>; + const DatePickerAndroid = { - async open(options: Object): Promise { + async open(options: Options): Promise { return Promise.reject({ message: 'DatePickerAndroid is not supported on this platform.', });