Skip to content

Commit 7385b46

Browse files
corbtpglotov
authored andcommitted
Resolve react flow definitions
Summary:Currently, we're not taking advantage of Flow's built-in type definitions for the React library in all cases because Flow's definition uses `declare module react` and this file uses `import('React')`, which Flow thinks is a different library. After this change, the following starts working which didn't before: ```js import { Component } from 'react-native'; class MyText extends Component<void, {text: string}, void> { render() { return <Text>{this.props.text}</Text> } } // Correctly throws a Flow error for the missing "text" prop const renderedText = <MyText />; ``` Closes facebook#5489 Differential Revision: D2856176 fb-gh-sync-id: 473ca188ad7d990c3e765526c4b33caf49ad9ffd shipit-source-id: 473ca188ad7d990c3e765526c4b33caf49ad9ffd
1 parent 8217a4a commit 7385b46

22 files changed

+74
-22
lines changed

.flowconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ Libraries/react-native/react-native-interface.js
4848
[options]
4949
module.system=haste
5050

51+
esproposal.class_static_fields=enable
52+
esproposal.class_instance_fields=enable
53+
5154
munge_underscores=true
5255

5356
module.name_mapper='^image![a-zA-Z0-9$_-]+$' -> 'GlobalImageStub'

Examples/2048/Game2048.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class Board extends React.Component {
5353
}
5454

5555
class Tile extends React.Component {
56+
state: any;
57+
5658
static _getPosition(index): number {
5759
return BOARD_PADDING + (index * (CELL_SIZE + CELL_MARGIN * 2) + CELL_MARGIN);
5860
}
@@ -147,6 +149,7 @@ class GameEndOverlay extends React.Component {
147149
class Game2048 extends React.Component {
148150
startX: number;
149151
startY: number;
152+
state: any;
150153

151154
constructor(props: {}) {
152155
super(props);

Examples/UIExplorer/AlertIOSExample.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ exports.examples = [{
3737
},
3838
{
3939
title: 'Prompt Options',
40-
render(): React.Component {
40+
render(): ReactElement {
4141
return <PromptOptions />;
4242
}
4343
},
@@ -85,9 +85,13 @@ exports.examples = [{
8585
}];
8686

8787
class PromptOptions extends React.Component {
88+
state: any;
89+
customButtons: Array<Object>;
90+
8891
constructor(props) {
8992
super(props);
9093

94+
// $FlowFixMe this seems to be a Flow bug, `saveResponse` is defined below
9195
this.saveResponse = this.saveResponse.bind(this);
9296

9397
this.customButtons = [{

Examples/UIExplorer/AnimatedExample.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ exports.examples = [
3939
'mounts.',
4040
render: function() {
4141
class FadeInView extends React.Component {
42+
state: any;
43+
4244
constructor(props) {
4345
super(props);
4446
this.state = {
@@ -66,6 +68,8 @@ exports.examples = [
6668
}
6769
}
6870
class FadeInExample extends React.Component {
71+
state: any;
72+
6973
constructor(props) {
7074
super(props);
7175
this.state = {

Examples/UIExplorer/AnimatedGratuitousApp/AnExApp.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ var CIRCLE_MARGIN = 18;
3232
var NUM_CIRCLES = 30;
3333

3434
class Circle extends React.Component {
35+
state: any;
36+
props: any;
37+
longTimer: number;
38+
3539
_onLongPress: () => void;
3640
_toggleIsActive: () => void;
3741
constructor(props: Object): void {
@@ -156,6 +160,13 @@ class Circle extends React.Component {
156160
}
157161

158162
class AnExApp extends React.Component {
163+
state: any;
164+
props: any;
165+
166+
static title = 'Animated - Gratuitous App';
167+
static description = 'Bunch of Animations - tap a circle to ' +
168+
'open a view with more animations, or longPress and drag to reorder circles.';
169+
159170
_onMove: (position: Point) => void;
160171
constructor(props: any): void {
161172
super(props);
@@ -266,10 +277,6 @@ function moveToClosest({activeKey, keys, restLayouts}, position) {
266277
}
267278
}
268279

269-
AnExApp.title = 'Animated - Gratuitous App';
270-
AnExApp.description = 'Bunch of Animations - tap a circle to ' +
271-
'open a view with more animations, or longPress and drag to reorder circles.';
272-
273280
var styles = StyleSheet.create({
274281
container: {
275282
flex: 1,

Examples/UIExplorer/AnimatedGratuitousApp/AnExBobble.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ var BOBBLE_SPOTS = [...Array(NUM_BOBBLES)].map((_, i) => { // static positions
3636
});
3737

3838
class AnExBobble extends React.Component {
39+
state: any;
40+
3941
constructor(props: Object) {
4042
super(props);
4143
this.state = {};

Examples/UIExplorer/AnimatedGratuitousApp/AnExChained.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ var {
2626
} = React;
2727

2828
class AnExChained extends React.Component {
29+
state: any;
30+
2931
constructor(props: Object) {
3032
super(props);
3133
this.state = {

Examples/UIExplorer/AnimatedGratuitousApp/AnExScroll.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1313
*
1414
* @providesModule AnExScroll
15+
* @flow
1516
*/
1617
'use strict';
1718

@@ -26,12 +27,7 @@ var {
2627
} = React;
2728

2829
class AnExScroll extends React.Component {
29-
constructor(props) {
30-
super(props);
31-
this.state = {
32-
scrollX: new Animated.Value(0),
33-
};
34-
}
30+
state: any = { scrollX: new Animated.Value(0) };
3531

3632
render() {
3733
var width = this.props.panelWidth;

Examples/UIExplorer/AnimatedGratuitousApp/AnExSet.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ var AnExScroll = require('./AnExScroll');
3131
var AnExTilt = require('./AnExTilt');
3232

3333
class AnExSet extends React.Component {
34+
state: any;
35+
3436
constructor(props: Object) {
3537
super(props);
3638
function randColor() {

Examples/UIExplorer/AnimatedGratuitousApp/AnExTilt.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ var {
2626
} = React;
2727

2828
class AnExTilt extends React.Component {
29+
state: any;
30+
2931
constructor(props: Object) {
3032
super(props);
3133
this.state = {

0 commit comments

Comments
 (0)