Strengthening Flow Types for Core Components
See original GitHub issueWe want to tighten the Flow types of the props for our core components. We need the help of the community to comb through these files and improve these types.
Right now a lot of props are typed using any
, Function
, or Object
.
These types can cause flow to silently skip over portions of your code, which would have otherwise caused type errors. - From eslint-plugin-flowtype
Many of these types are used to validate what we send to native. If JS defines a function that expects a string but Native calls it with a number, applications can crash.
We’d like to fix that by removing all references to any
, Function
, or Object
. While we ideally want to remove all references of these files from the codebase, there are a lot, so we should prioritize the ones that are used in the props type definitions for components. 😄
If your are able to remove all of these weak types from the file, try to change @flow
at the top of the file to @flow strict-local
. That should ensure that weak types can’t come back to these files in the future.
Step 1, Step 2, and Step 3 helped prepare our components for this step.
How to submit quality PRs
Since many of these weak types are used at the boundary between JS and native, you will likely need to read through the native code for these components to see how these props are being used. Unfortunately, Flow will likely pass with invalid types. Paying close attention to what iOS and Android expects will be helpful to ensure the types are accurate.
I also urge those that submit PRs for this to help out with reviewing the PRs for this issue from other contributors. Code review is a great opportunity to learn and improve your own code as well as make sure everyone is on the same page and consistent. If you find tips that would have helped you investigate and improve the types, commenting on this issue with those tips would be appreciated. Help each other. ❤️
Also note that since you are improving these types you will likely help catch a bunch of bugs at Facebook (and elsewhere) where code isn’t handling the types correctly. This means that PRs will likely take longer to land then the other issues like this we have asked for help on. This is a good thing, it is direct impact on the stability of React Native projects and catching bugs.
The files
The following is a list of files that I’d like to address first. If you want to take one of these files please comment on this issue with the file name so that others don’t work on it as well and waste work. There are plenty of files to go around. 😄
Also, TextProps.js
and ViewPropTypes.js
are probably the files with the most changes necessary. I don’t really expect those to be done by one person. Feel free to type a few and send a PR. Once that PR is landed someone else can take it on and type a few more.
- Libraries/Text/TextProps.js
- Libraries/Components/CheckBox/CheckBox.android.js
- Libraries/Components/DatePicker/DatePickerIOS.ios.js
- Libraries/Components/DatePickerAndroid/DatePickerAndroid.android.js
- Libraries/Components/DatePickerAndroid/DatePickerAndroid.ios.js
- Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js
- Libraries/Components/Keyboard/Keyboard.js
- Libraries/Components/Picker/Picker.js
- Libraries/Components/Picker/PickerAndroid.android.js
- Libraries/Components/Picker/PickerIOS.ios.js
- Libraries/Components/RefreshControl/RefreshControl.js
- Libraries/Components/ScrollResponder.js
- Libraries/Components/ScrollView/mocks/ScrollViewMock.js
- Libraries/Components/ScrollView/ScrollView.js
- Libraries/Components/SegmentedControlIOS/SegmentedControlIOS.ios.js
- Libraries/Components/Slider/Slider.js
- Libraries/Components/StaticContainer.react.js
- Libraries/Components/StatusBar/StatusBar.js
- Libraries/Components/TextInput/TextInput.js
- Libraries/Components/TimePickerAndroid/TimePickerAndroid.android.js
- Libraries/Components/TimePickerAndroid/TimePickerAndroid.ios.js
- Libraries/Components/Touchable/TouchableBounce.js
- Libraries/Components/Touchable/TouchableHighlight.js
- Libraries/Components/Touchable/TouchableNativeFeedback.android.js
- Libraries/Components/Touchable/TouchableOpacity.js
- Libraries/Components/Touchable/TouchableWithoutFeedback.js
- Libraries/Components/View/ViewPropTypes.js
- Libraries/Components/ViewPager/ViewPagerAndroid.android.js
All the warnings for these files:
Libraries/Text/TextProps.js
109:23 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
110:22 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
111:25 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
112:27 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
113:36 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
114:32 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/CheckBox/CheckBox.android.js
121:30 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/DatePicker/DatePickerIOS.ios.js
27:14 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/DatePickerAndroid/DatePickerAndroid.android.js
18:29 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
68:30 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
68:47 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/DatePickerAndroid/DatePickerAndroid.ios.js
14:23 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
14:40 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js
155:32 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/Keyboard/Keyboard.js
124:58 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/Picker/Picker.js
35:11 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
66:19 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
73:31 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/Picker/PickerAndroid.android.js
37:19 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
40:31 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/Picker/PickerIOS.ios.js
30:15 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
37:11 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
65:31 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
66:18 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
76:12 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/RefreshControl/RefreshControl.js
90:16 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/ScrollResponder.js
116:14 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
412:49 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
537:17 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/ScrollView/__mocks__/ScrollViewMock.js
15:19 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/ScrollView/InternalScrollViewType.js
29:25 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
30:24 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
31:23 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
34:17 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/ScrollView/ScrollView.js
224:20 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
407:28 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
411:26 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
417:15 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
421:24 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
426:22 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
436:26 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
595:35 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
609:34 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
613:33 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
738:30 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
765:30 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
774:39 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/SegmentedControlIOS/SegmentedControlIOS.ios.js
36:20 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
37:15 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
45:14 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/Slider/Slider.js
27:14 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
121:20 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
128:24 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/StaticContainer.react.js
30:47 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
31:36 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/StatusBar/StatusBar.js
110:21 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
111:18 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
112:4 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
127:34 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
127:40 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/TextInput/TextInput.js
58:14 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
187:13 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
188:14 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
189:15 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
190:19 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
191:26 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
192:18 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
193:19 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
194:24 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
195:22 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
196:17 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
197:15 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
795:22 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
900:32 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/TimePickerAndroid/TimePickerAndroid.android.js
55:30 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
55:47 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/TimePickerAndroid/TimePickerAndroid.ios.js
14:23 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
14:40 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/Touchable/TouchableBounce.js
27:14 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
39:28 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
40:31 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
98:17 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
150:37 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/Touchable/TouchableHighlight.js
42:27 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
52:21 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
53:21 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/Touchable/TouchableNativeFeedback.android.js
41:14 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/Touchable/TouchableOpacity.js
28:14 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
34:27 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/Touchable/TouchableWithoutFeedback.js
45:32 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
47:13 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
48:7 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
61:13 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
62:14 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
63:15 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
64:18 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
65:14 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
66:16 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
67:17 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
180:57 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
209:37 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/View/ViewPropTypes.js
35:28 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
43:25 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
64:17 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
68:20 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
69:27 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
70:17 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
71:24 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
72:18 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
73:25 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
74:19 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
75:26 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
93:31 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
104:38 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
115:23 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
125:22 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
136:24 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
146:25 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
148:23 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
149:21 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
162:27 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
173:36 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
183:32 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
194:39 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
198:30 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
199:30 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/ViewPager/ViewPagerAndroid.android.js
26:14 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
50:19 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
60:31 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
68:21 warning The `Function` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Libraries/Components/WebView/WebView.ios.js
57:11 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
58:9 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
59:16 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
62:14 warning The `Object` type is too generic and could lead to hard to debug errors. Please use only as a last resort
659:26 warning The `any` type is too generic and could lead to hard to debug errors. Please use only as a last resort
Issue Analytics
- State:
- Created 5 years ago
- Reactions:12
- Comments:47 (38 by maintainers)
Top GitHub Comments
I’ll take
Libraries/Components/WebView/WebView.ios.js
I’ll take
Libraries/Components/StatusBar/StatusBar.js