Skip to content

Commit 76a2ca4

Browse files
deecewanfacebook-github-bot
authored andcommitted
Fix some flow errors that appear
Summary: <!-- Thank you for sending the PR! We appreciate you spending the time to work on these changes. Help us understand your motivation by explaining why you decided to make this change. You can learn more about contributing to React Native here: http://facebook.github.io/react-native/docs/contributing.html Happy contributing! --> There are some errors I noticed after upgrading my flow version. I had them in my project, and they were also reported in #11655. These errors were ignored on master, but I went through and fixed them so the static analysis will work still. After these changes, I receive no errors using flow `0.60.1` on latest master, or using `0.59` in my local project (which does not have the requisite ignores included). - init a new project `react-native init --version <path-to-repo> helloworld` - add the flow binary `yarn add -D flow-bin` - run flow `yarn flow` - make sure there are no errors in the project. ``` No errors! ✨ Done in 23.60s. ``` <!-- Help reviewers and the release process by writing your own release notes **INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.** CATEGORY [----------] TYPE [ CLI ] [-------------] LOCATION [ DOCS ] [ BREAKING ] [-------------] [ GENERAL ] [ BUGFIX ] [-{Component}-] [ INTERNAL ] [ ENHANCEMENT ] [ {File} ] [ IOS ] [ FEATURE ] [ {Directory} ] |-----------| [ ANDROID ] [ MINOR ] [ {Framework} ] - | {Message} | [----------] [-------------] [-------------] |-----------| [CATEGORY] [TYPE] [LOCATION] - MESSAGE EXAMPLES: [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see --> [GENERAL][BUGFIX][./Libraries] - Fix up some flow definitions Closes #17086 Differential Revision: D6509112 Pulled By: hramos fbshipit-source-id: a61145b5306c666ab6510ccb9eea02d96f3decb3
1 parent 1988ba1 commit 76a2ca4

File tree

3 files changed

+53
-77
lines changed

3 files changed

+53
-77
lines changed

Libraries/Animated/src/Easing.js

+10-51
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,14 @@ class Easing {
6262
/**
6363
* A stepping function, returns 1 for any positive value of `n`.
6464
*/
65-
/* $FlowFixMe(>=0.59.0 site=react_native_fb) This comment suppresses an error
66-
* caught by Flow 0.59 which was not caught before. Most likely, this error
67-
* is because an exported function parameter is missing an annotation.
68-
* Without an annotation, these parameters are uncovered by Flow. */
69-
static step0(n) {
65+
static step0(n: number) {
7066
return n > 0 ? 1 : 0;
7167
}
7268

7369
/**
7470
* A stepping function, returns 1 if `n` is greater than or equal to 1.
7571
*/
76-
/* $FlowFixMe(>=0.59.0 site=react_native_fb) This comment suppresses an error
77-
* caught by Flow 0.59 which was not caught before. Most likely, this error
78-
* is because an exported function parameter is missing an annotation.
79-
* Without an annotation, these parameters are uncovered by Flow. */
80-
static step1(n) {
72+
static step1(n: number) {
8173
return n >= 1 ? 1 : 0;
8274
}
8375

@@ -87,11 +79,7 @@ class Easing {
8779
*
8880
* http://cubic-bezier.com/#0,0,1,1
8981
*/
90-
/* $FlowFixMe(>=0.59.0 site=react_native_fb) This comment suppresses an error
91-
* caught by Flow 0.59 which was not caught before. Most likely, this error
92-
* is because an exported function parameter is missing an annotation.
93-
* Without an annotation, these parameters are uncovered by Flow. */
94-
static linear(t) {
82+
static linear(t: number) {
9583
return t;
9684
}
9785

@@ -114,11 +102,7 @@ class Easing {
114102
*
115103
* http://easings.net/#easeInQuad
116104
*/
117-
/* $FlowFixMe(>=0.59.0 site=react_native_fb) This comment suppresses an error
118-
* caught by Flow 0.59 which was not caught before. Most likely, this error
119-
* is because an exported function parameter is missing an annotation.
120-
* Without an annotation, these parameters are uncovered by Flow. */
121-
static quad(t) {
105+
static quad(t: number) {
122106
return t * t;
123107
}
124108

@@ -128,11 +112,7 @@ class Easing {
128112
*
129113
* http://easings.net/#easeInCubic
130114
*/
131-
/* $FlowFixMe(>=0.59.0 site=react_native_fb) This comment suppresses an error
132-
* caught by Flow 0.59 which was not caught before. Most likely, this error
133-
* is because an exported function parameter is missing an annotation.
134-
* Without an annotation, these parameters are uncovered by Flow. */
135-
static cubic(t) {
115+
static cubic(t: number) {
136116
return t * t * t;
137117
}
138118

@@ -142,29 +122,16 @@ class Easing {
142122
* n = 4: http://easings.net/#easeInQuart
143123
* n = 5: http://easings.net/#easeInQuint
144124
*/
145-
/* $FlowFixMe(>=0.59.0 site=react_native_fb) This comment suppresses an error
146-
* caught by Flow 0.59 which was not caught before. Most likely, this error
147-
* is because an exported function parameter is missing an annotation.
148-
* Without an annotation, these parameters are uncovered by Flow. */
149-
static poly(n) {
150-
/* $FlowFixMe(>=0.59.0 site=react_native_fb) This comment suppresses an
151-
* error caught by Flow 0.59 which was not caught before. Most likely, this
152-
* error is because an exported function parameter is missing an
153-
* annotation. Without an annotation, these parameters are uncovered by
154-
* Flow. */
155-
return (t) => Math.pow(t, n);
125+
static poly(n: number) {
126+
return (t: number) => Math.pow(t, n);
156127
}
157128

158129
/**
159130
* A sinusoidal function.
160131
*
161132
* http://easings.net/#easeInSine
162133
*/
163-
/* $FlowFixMe(>=0.59.0 site=react_native_fb) This comment suppresses an error
164-
* caught by Flow 0.59 which was not caught before. Most likely, this error
165-
* is because an exported function parameter is missing an annotation.
166-
* Without an annotation, these parameters are uncovered by Flow. */
167-
static sin(t) {
134+
static sin(t: number) {
168135
return 1 - Math.cos(t * Math.PI / 2);
169136
}
170137

@@ -173,11 +140,7 @@ class Easing {
173140
*
174141
* http://easings.net/#easeInCirc
175142
*/
176-
/* $FlowFixMe(>=0.59.0 site=react_native_fb) This comment suppresses an error
177-
* caught by Flow 0.59 which was not caught before. Most likely, this error
178-
* is because an exported function parameter is missing an annotation.
179-
* Without an annotation, these parameters are uncovered by Flow. */
180-
static circle(t) {
143+
static circle(t: number) {
181144
return 1 - Math.sqrt(1 - t * t);
182145
}
183146

@@ -186,11 +149,7 @@ class Easing {
186149
*
187150
* http://easings.net/#easeInExpo
188151
*/
189-
/* $FlowFixMe(>=0.59.0 site=react_native_fb) This comment suppresses an error
190-
* caught by Flow 0.59 which was not caught before. Most likely, this error
191-
* is because an exported function parameter is missing an annotation.
192-
* Without an annotation, these parameters are uncovered by Flow. */
193-
static exp(t) {
152+
static exp(t: number) {
194153
return Math.pow(2, 10 * (t - 1));
195154
}
196155

Libraries/CameraRoll/CameraRoll.js

+41-7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ const ASSET_TYPE_OPTIONS = {
3535
Photos: 'Photos',
3636
};
3737

38+
type GetPhotosParams = {
39+
first: number,
40+
after?: string,
41+
groupTypes?: $Keys<typeof GROUP_TYPES_OPTIONS>,
42+
groupName?: string,
43+
assetType?: $Keys<typeof ASSET_TYPE_OPTIONS>,
44+
mimeTypes?: Array<string>,
45+
};
46+
3847
/**
3948
* Shape of the param arg for the `getPhotos` function.
4049
*/
@@ -73,6 +82,35 @@ const getPhotosParamChecker = createStrictShapeTypeChecker({
7382
mimeTypes: PropTypes.arrayOf(PropTypes.string),
7483
});
7584

85+
type GetPhotosReturn = Promise<{
86+
edges: Array<{
87+
node: {
88+
type: string,
89+
group_name: string,
90+
image: {
91+
uri: string,
92+
height: number,
93+
width: number,
94+
isStored?: boolean,
95+
playableDuration: number,
96+
},
97+
timestamp: number,
98+
location?: {
99+
latitude?: number,
100+
longitude?: number,
101+
altitude?: number,
102+
heading?: number,
103+
speed?: number,
104+
},
105+
},
106+
}>,
107+
page_info: {
108+
has_next_page: boolean,
109+
start_cursor?: string,
110+
end_cursor?: string,
111+
},
112+
}>;
113+
76114
/**
77115
* Shape of the return value of the `getPhotos` function.
78116
*/
@@ -162,8 +200,8 @@ class CameraRoll {
162200

163201
invariant(
164202
type === 'photo' || type === 'video' || type === undefined,
165-
// $FlowFixMe(>=0.28.0)
166-
`The second argument to saveToCameraRoll must be 'photo' or 'video'. You passed ${type}`,
203+
`The second argument to saveToCameraRoll must be 'photo' or 'video'. You passed ${type ||
204+
'unknown'}`,
167205
);
168206

169207
let mediaType = 'photo';
@@ -259,11 +297,7 @@ class CameraRoll {
259297
* }
260298
* ```
261299
*/
262-
/* $FlowFixMe(>=0.59.0 site=react_native_fb) This comment suppresses an error
263-
* caught by Flow 0.59 which was not caught before. Most likely, this error
264-
* is because an exported function parameter is missing an annotation.
265-
* Without an annotation, these parameters are uncovered by Flow. */
266-
static getPhotos(params) {
300+
static getPhotos(params: GetPhotosParams): GetPhotosReturn {
267301
if (__DEV__) {
268302
checkPropTypes(
269303
{params: getPhotosParamChecker},

Libraries/StyleSheet/StyleSheetValidation.js

+2-19
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,14 @@ var invariant = require('fbjs/lib/invariant');
2424
const ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
2525

2626
class StyleSheetValidation {
27-
/* $FlowFixMe(>=0.59.0 site=react_native_fb) This comment suppresses an error
28-
* caught by Flow 0.59 which was not caught before. Most likely, this error
29-
* is because an exported function parameter is missing an annotation.
30-
* Without an annotation, these parameters are uncovered by Flow. */
31-
static validateStyleProp(prop, style, caller) {
27+
static validateStyleProp(prop: string, style: Object, caller: string) {
3228
if (!__DEV__) {
3329
return;
3430
}
3531
if (allStylePropTypes[prop] === undefined) {
3632
var message1 = '"' + prop + '" is not a valid style property.';
3733
var message2 = '\nValid style props: ' +
3834
JSON.stringify(Object.keys(allStylePropTypes).sort(), null, ' ');
39-
/* $FlowFixMe(>=0.56.0 site=react_native_oss) This comment suppresses an
40-
* error found when Flow v0.56 was deployed. To see the error delete this
41-
* comment and run Flow. */
4235
styleError(message1, style, caller, message2);
4336
}
4437
var error = allStylePropTypes[prop](
@@ -50,21 +43,11 @@ class StyleSheetValidation {
5043
ReactPropTypesSecret,
5144
);
5245
if (error) {
53-
/* $FlowFixMe(>=0.56.0 site=react_native_oss) This comment suppresses an
54-
* error found when Flow v0.56 was deployed. To see the error delete this
55-
* comment and run Flow. */
56-
/* $FlowFixMe(>=0.56.0 site=react_native_fb,react_native_oss) This
57-
* comment suppresses an error found when Flow v0.56 was deployed. To see
58-
* the error delete this comment and run Flow. */
5946
styleError(error.message, style, caller);
6047
}
6148
}
6249

63-
/* $FlowFixMe(>=0.59.0 site=react_native_fb) This comment suppresses an error
64-
* caught by Flow 0.59 which was not caught before. Most likely, this error
65-
* is because an exported function parameter is missing an annotation.
66-
* Without an annotation, these parameters are uncovered by Flow. */
67-
static validateStyle(name, styles) {
50+
static validateStyle(name: string, styles: Object) {
6851
if (!__DEV__) {
6952
return;
7053
}

0 commit comments

Comments
 (0)