From e640637928c91a05ec3d07e9bb0705d81755d7c6 Mon Sep 17 00:00:00 2001 From: Eli White Date: Mon, 14 Oct 2019 13:51:51 -0700 Subject: [PATCH] Core: Remove `any` from calls to requireNativeComponent Summary: These were being cast to a NativeComponent but that is no longer accurate. `requireNativeComponent` returns the type of `HostComponent` now which is more accurate. We don't need the cast through `any` anymore. In order to know that I found all the callsites, I ran this command to find these: ``` grep -r "requireNativeComponent" react-native-github -C 5 | grep 'any' ``` Changelog: [Internal] Reviewed By: cpojer Differential Revision: D17864165 fbshipit-source-id: 3774d6d47d7bb0d885cc1a1352f81fec7d3bca0d --- .../AndroidCheckBoxNativeComponent.js | 10 +++---- .../RCTDatePickerNativeComponent.js | 9 ++++--- .../AndroidDialogPickerNativeComponent.js | 10 +++---- .../AndroidDropdownPickerNativeComponent.js | 10 +++---- Libraries/Components/Picker/PickerIOS.ios.js | 15 +---------- .../Picker/RCTPickerNativeComponent.js | 26 +++++++++---------- .../AndroidTextInputNativeComponent.js | 10 +++---- .../RCTTest/RCTSnapshotNativeComponent.js | 10 +++---- 8 files changed, 44 insertions(+), 56 deletions(-) diff --git a/Libraries/Components/CheckBox/AndroidCheckBoxNativeComponent.js b/Libraries/Components/CheckBox/AndroidCheckBoxNativeComponent.js index 097cba17600..c6e4152e825 100644 --- a/Libraries/Components/CheckBox/AndroidCheckBoxNativeComponent.js +++ b/Libraries/Components/CheckBox/AndroidCheckBoxNativeComponent.js @@ -11,9 +11,9 @@ const requireNativeComponent = require('../../ReactNative/requireNativeComponent'); +import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes'; import type {ViewProps} from '../View/ViewPropTypes'; import type {SyntheticEvent} from '../../Types/CoreEventTypes'; -import type {NativeComponent} from '../../Renderer/shims/ReactNative'; type CheckBoxEvent = SyntheticEvent< $ReadOnly<{| @@ -45,8 +45,8 @@ type NativeProps = $ReadOnly<{| tintColors: {|true: ?number, false: ?number|} | typeof undefined, |}>; -type CheckBoxNativeType = Class>; - -module.exports = ((requireNativeComponent( +const AndroidCheckBoxNativeComponent: HostComponent = requireNativeComponent( 'AndroidCheckBox', -): any): CheckBoxNativeType); +); + +module.exports = AndroidCheckBoxNativeComponent; diff --git a/Libraries/Components/DatePicker/RCTDatePickerNativeComponent.js b/Libraries/Components/DatePicker/RCTDatePickerNativeComponent.js index df605f19b08..41d0f836897 100644 --- a/Libraries/Components/DatePicker/RCTDatePickerNativeComponent.js +++ b/Libraries/Components/DatePicker/RCTDatePickerNativeComponent.js @@ -12,9 +12,9 @@ const requireNativeComponent = require('../../ReactNative/requireNativeComponent'); +import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes'; import type {SyntheticEvent} from '../../Types/CoreEventTypes'; import type {ViewProps} from '../View/ViewPropTypes'; -import type {NativeComponent} from '../../Renderer/shims/ReactNative'; type Event = SyntheticEvent< $ReadOnly<{| @@ -34,8 +34,9 @@ type NativeProps = $ReadOnly<{| onChange?: ?(event: Event) => void, timeZoneOffsetInMinutes?: ?number, |}>; -type RCTDatePickerNativeType = Class>; -module.exports = ((requireNativeComponent( +const RCTDatePickerNativeComponent: HostComponent = requireNativeComponent( 'RCTDatePicker', -): any): RCTDatePickerNativeType); +); + +module.exports = RCTDatePickerNativeComponent; diff --git a/Libraries/Components/Picker/AndroidDialogPickerNativeComponent.js b/Libraries/Components/Picker/AndroidDialogPickerNativeComponent.js index dd5f5a10912..8c74288f775 100644 --- a/Libraries/Components/Picker/AndroidDialogPickerNativeComponent.js +++ b/Libraries/Components/Picker/AndroidDialogPickerNativeComponent.js @@ -17,9 +17,9 @@ import type { Int32, WithDefault, } from '../../Types/CodegenTypes'; +import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes'; import type {TextStyleProp} from '../../StyleSheet/StyleSheet'; import type {ColorValue} from '../../StyleSheet/StyleSheetTypes'; -import type {NativeComponent} from '../../Renderer/shims/ReactNative'; import type {ViewProps} from '../../Components/View/ViewPropTypes'; type PickerItem = $ReadOnly<{| @@ -46,8 +46,8 @@ type NativeProps = $ReadOnly<{| onSelect?: DirectEventHandler, |}>; -type ReactPicker = Class>; - -module.exports = ((requireNativeComponent( +const AndroidDialogPickerNativeComponent: HostComponent = requireNativeComponent( 'AndroidDialogPicker', -): any): ReactPicker); +); + +module.exports = AndroidDialogPickerNativeComponent; diff --git a/Libraries/Components/Picker/AndroidDropdownPickerNativeComponent.js b/Libraries/Components/Picker/AndroidDropdownPickerNativeComponent.js index 8f3976b4a66..82f455c2fb5 100644 --- a/Libraries/Components/Picker/AndroidDropdownPickerNativeComponent.js +++ b/Libraries/Components/Picker/AndroidDropdownPickerNativeComponent.js @@ -17,9 +17,9 @@ import type { Int32, WithDefault, } from '../../Types/CodegenTypes'; +import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes'; import type {TextStyleProp} from '../../StyleSheet/StyleSheet'; import type {ColorValue} from '../../StyleSheet/StyleSheetTypes'; -import type {NativeComponent} from '../../Renderer/shims/ReactNative'; import type {ViewProps} from '../../Components/View/ViewPropTypes'; type PickerItem = $ReadOnly<{| @@ -46,8 +46,8 @@ type NativeProps = $ReadOnly<{| onSelect?: DirectEventHandler, |}>; -type ReactPicker = Class>; - -module.exports = ((requireNativeComponent( +const AndroidDropdownPickerNativeComponent: HostComponent = requireNativeComponent( 'AndroidDropdownPicker', -): any): ReactPicker); +); + +module.exports = AndroidDropdownPickerNativeComponent; diff --git a/Libraries/Components/Picker/PickerIOS.ios.js b/Libraries/Components/Picker/PickerIOS.ios.js index 340069908be..0b5df5bc7d1 100644 --- a/Libraries/Components/Picker/PickerIOS.ios.js +++ b/Libraries/Components/Picker/PickerIOS.ios.js @@ -15,7 +15,6 @@ const RCTPickerNativeComponent = require('./RCTPickerNativeComponent'); const React = require('react'); -const ReactNative = require('../../Renderer/shims/ReactNative'); const StyleSheet = require('../../StyleSheet/StyleSheet'); const View = require('../View/View'); @@ -39,18 +38,6 @@ type RCTPickerIOSItemType = $ReadOnly<{| textColor: ?number, |}>; -type RCTPickerIOSType = Class< - ReactNative.NativeComponent< - $ReadOnly<{| - items: $ReadOnlyArray, - onChange: (event: PickerIOSChangeEvent) => void, - selectedIndex: number, - style?: ?TextStyleProp, - testID?: ?string, - |}>, - >, ->; - type Label = Stringish | number; type Props = $ReadOnly<{| @@ -78,7 +65,7 @@ const PickerIOSItem = (props: ItemProps): null => { }; class PickerIOS extends React.Component { - _picker: ?React.ElementRef = null; + _picker: ?React.ElementRef = null; state: State = { selectedIndex: 0, diff --git a/Libraries/Components/Picker/RCTPickerNativeComponent.js b/Libraries/Components/Picker/RCTPickerNativeComponent.js index 541b1ccf221..eeccee096f0 100644 --- a/Libraries/Components/Picker/RCTPickerNativeComponent.js +++ b/Libraries/Components/Picker/RCTPickerNativeComponent.js @@ -11,9 +11,9 @@ const requireNativeComponent = require('../../ReactNative/requireNativeComponent'); +import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes'; import type {SyntheticEvent} from '../../Types/CoreEventTypes'; import type {TextStyleProp} from '../../StyleSheet/StyleSheet'; -import type {NativeComponent} from '../../Renderer/shims/ReactNative'; type PickerIOSChangeEvent = SyntheticEvent< $ReadOnly<{| @@ -30,16 +30,16 @@ type RCTPickerIOSItemType = $ReadOnly<{| type Label = Stringish | number; -type RCTPickerIOSType = Class< - NativeComponent< - $ReadOnly<{| - items: $ReadOnlyArray, - onChange: (event: PickerIOSChangeEvent) => void, - selectedIndex: number, - style?: ?TextStyleProp, - testID?: ?string, - |}>, - >, ->; +type NativeProps = $ReadOnly<{| + items: $ReadOnlyArray, + onChange: (event: PickerIOSChangeEvent) => void, + selectedIndex: number, + style?: ?TextStyleProp, + testID?: ?string, +|}>; -module.exports = ((requireNativeComponent('RCTPicker'): any): RCTPickerIOSType); +const RCTPickerNativeComponent: HostComponent = requireNativeComponent( + 'RCTPicker', +); + +module.exports = RCTPickerNativeComponent; diff --git a/Libraries/Components/TextInput/AndroidTextInputNativeComponent.js b/Libraries/Components/TextInput/AndroidTextInputNativeComponent.js index 8a495c6cdae..d08573f119d 100644 --- a/Libraries/Components/TextInput/AndroidTextInputNativeComponent.js +++ b/Libraries/Components/TextInput/AndroidTextInputNativeComponent.js @@ -19,7 +19,7 @@ import type { Int32, WithDefault, } from 'react-native/Libraries/Types/CodegenTypes'; -import type {NativeComponent} from '../../Renderer/shims/ReactNative'; +import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes'; import type {TextStyleProp, ViewStyleProp} from '../../StyleSheet/StyleSheet'; import type {ColorValue} from '../../StyleSheet/StyleSheetTypes'; import {requireNativeComponent} from 'react-native'; @@ -534,8 +534,8 @@ export type NativeProps = $ReadOnly<{| text?: ?string, |}>; -type AndroidTextInputComponentType = Class>; - -export default ((requireNativeComponent( +const AndroidTextInputNativeComponent: HostComponent = requireNativeComponent( 'AndroidTextInput', -): any): AndroidTextInputComponentType); +); + +export default AndroidTextInputNativeComponent; diff --git a/RNTester/RCTTest/RCTSnapshotNativeComponent.js b/RNTester/RCTTest/RCTSnapshotNativeComponent.js index d39de655467..9cd05e5637f 100644 --- a/RNTester/RCTTest/RCTSnapshotNativeComponent.js +++ b/RNTester/RCTTest/RCTSnapshotNativeComponent.js @@ -12,9 +12,9 @@ const {requireNativeComponent} = require('react-native'); +import type {HostComponent} from '../../Libraries/Renderer/shims/ReactNativeTypes'; import type {SyntheticEvent} from '../../Libraries/Types/CoreEventTypes'; import type {ViewProps} from '../../Libraries/Components/View/ViewPropTypes'; -import type {NativeComponent} from '../../Libraries/Renderer/shims/ReactNative'; type SnapshotReadyEvent = SyntheticEvent< $ReadOnly<{ @@ -28,8 +28,8 @@ type NativeProps = $ReadOnly<{| testIdentifier?: ?string, |}>; -type SnapshotViewNativeType = Class>; - -module.exports = ((requireNativeComponent( +const RCTSnapshotNativeComponent: HostComponent = requireNativeComponent( 'RCTSnapshot', -): any): SnapshotViewNativeType); +); + +module.exports = RCTSnapshotNativeComponent;