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 https://github.com/facebook/react-native/pull/17086

Differential Revision: D6509112

Pulled By: hramos

fbshipit-source-id: a61145b5306c666ab6510ccb9eea02d96f3decb3
This commit is contained in:
David Buchan-Swanson 2017-12-07 08:22:47 -08:00 committed by Facebook Github Bot
parent 1988ba1d79
commit 76a2ca4c9c
3 changed files with 53 additions and 77 deletions

View File

@ -62,22 +62,14 @@ class Easing {
/**
* A stepping function, returns 1 for any positive value of `n`.
*/
/* $FlowFixMe(>=0.59.0 site=react_native_fb) This comment suppresses an error
* caught by Flow 0.59 which was not caught before. Most likely, this error
* is because an exported function parameter is missing an annotation.
* Without an annotation, these parameters are uncovered by Flow. */
static step0(n) {
static step0(n: number) {
return n > 0 ? 1 : 0;
}
/**
* A stepping function, returns 1 if `n` is greater than or equal to 1.
*/
/* $FlowFixMe(>=0.59.0 site=react_native_fb) This comment suppresses an error
* caught by Flow 0.59 which was not caught before. Most likely, this error
* is because an exported function parameter is missing an annotation.
* Without an annotation, these parameters are uncovered by Flow. */
static step1(n) {
static step1(n: number) {
return n >= 1 ? 1 : 0;
}
@ -87,11 +79,7 @@ class Easing {
*
* http://cubic-bezier.com/#0,0,1,1
*/
/* $FlowFixMe(>=0.59.0 site=react_native_fb) This comment suppresses an error
* caught by Flow 0.59 which was not caught before. Most likely, this error
* is because an exported function parameter is missing an annotation.
* Without an annotation, these parameters are uncovered by Flow. */
static linear(t) {
static linear(t: number) {
return t;
}
@ -114,11 +102,7 @@ class Easing {
*
* http://easings.net/#easeInQuad
*/
/* $FlowFixMe(>=0.59.0 site=react_native_fb) This comment suppresses an error
* caught by Flow 0.59 which was not caught before. Most likely, this error
* is because an exported function parameter is missing an annotation.
* Without an annotation, these parameters are uncovered by Flow. */
static quad(t) {
static quad(t: number) {
return t * t;
}
@ -128,11 +112,7 @@ class Easing {
*
* http://easings.net/#easeInCubic
*/
/* $FlowFixMe(>=0.59.0 site=react_native_fb) This comment suppresses an error
* caught by Flow 0.59 which was not caught before. Most likely, this error
* is because an exported function parameter is missing an annotation.
* Without an annotation, these parameters are uncovered by Flow. */
static cubic(t) {
static cubic(t: number) {
return t * t * t;
}
@ -142,17 +122,8 @@ class Easing {
* n = 4: http://easings.net/#easeInQuart
* n = 5: http://easings.net/#easeInQuint
*/
/* $FlowFixMe(>=0.59.0 site=react_native_fb) This comment suppresses an error
* caught by Flow 0.59 which was not caught before. Most likely, this error
* is because an exported function parameter is missing an annotation.
* Without an annotation, these parameters are uncovered by Flow. */
static poly(n) {
/* $FlowFixMe(>=0.59.0 site=react_native_fb) This comment suppresses an
* error caught by Flow 0.59 which was not caught before. Most likely, this
* error is because an exported function parameter is missing an
* annotation. Without an annotation, these parameters are uncovered by
* Flow. */
return (t) => Math.pow(t, n);
static poly(n: number) {
return (t: number) => Math.pow(t, n);
}
/**
@ -160,11 +131,7 @@ class Easing {
*
* http://easings.net/#easeInSine
*/
/* $FlowFixMe(>=0.59.0 site=react_native_fb) This comment suppresses an error
* caught by Flow 0.59 which was not caught before. Most likely, this error
* is because an exported function parameter is missing an annotation.
* Without an annotation, these parameters are uncovered by Flow. */
static sin(t) {
static sin(t: number) {
return 1 - Math.cos(t * Math.PI / 2);
}
@ -173,11 +140,7 @@ class Easing {
*
* http://easings.net/#easeInCirc
*/
/* $FlowFixMe(>=0.59.0 site=react_native_fb) This comment suppresses an error
* caught by Flow 0.59 which was not caught before. Most likely, this error
* is because an exported function parameter is missing an annotation.
* Without an annotation, these parameters are uncovered by Flow. */
static circle(t) {
static circle(t: number) {
return 1 - Math.sqrt(1 - t * t);
}
@ -186,11 +149,7 @@ class Easing {
*
* http://easings.net/#easeInExpo
*/
/* $FlowFixMe(>=0.59.0 site=react_native_fb) This comment suppresses an error
* caught by Flow 0.59 which was not caught before. Most likely, this error
* is because an exported function parameter is missing an annotation.
* Without an annotation, these parameters are uncovered by Flow. */
static exp(t) {
static exp(t: number) {
return Math.pow(2, 10 * (t - 1));
}

View File

@ -35,6 +35,15 @@ const ASSET_TYPE_OPTIONS = {
Photos: 'Photos',
};
type GetPhotosParams = {
first: number,
after?: string,
groupTypes?: $Keys<typeof GROUP_TYPES_OPTIONS>,
groupName?: string,
assetType?: $Keys<typeof ASSET_TYPE_OPTIONS>,
mimeTypes?: Array<string>,
};
/**
* Shape of the param arg for the `getPhotos` function.
*/
@ -73,6 +82,35 @@ const getPhotosParamChecker = createStrictShapeTypeChecker({
mimeTypes: PropTypes.arrayOf(PropTypes.string),
});
type GetPhotosReturn = Promise<{
edges: Array<{
node: {
type: string,
group_name: string,
image: {
uri: string,
height: number,
width: number,
isStored?: boolean,
playableDuration: number,
},
timestamp: number,
location?: {
latitude?: number,
longitude?: number,
altitude?: number,
heading?: number,
speed?: number,
},
},
}>,
page_info: {
has_next_page: boolean,
start_cursor?: string,
end_cursor?: string,
},
}>;
/**
* Shape of the return value of the `getPhotos` function.
*/
@ -162,8 +200,8 @@ class CameraRoll {
invariant(
type === 'photo' || type === 'video' || type === undefined,
// $FlowFixMe(>=0.28.0)
`The second argument to saveToCameraRoll must be 'photo' or 'video'. You passed ${type}`,
`The second argument to saveToCameraRoll must be 'photo' or 'video'. You passed ${type ||
'unknown'}`,
);
let mediaType = 'photo';
@ -259,11 +297,7 @@ class CameraRoll {
* }
* ```
*/
/* $FlowFixMe(>=0.59.0 site=react_native_fb) This comment suppresses an error
* caught by Flow 0.59 which was not caught before. Most likely, this error
* is because an exported function parameter is missing an annotation.
* Without an annotation, these parameters are uncovered by Flow. */
static getPhotos(params) {
static getPhotos(params: GetPhotosParams): GetPhotosReturn {
if (__DEV__) {
checkPropTypes(
{params: getPhotosParamChecker},

View File

@ -24,11 +24,7 @@ var invariant = require('fbjs/lib/invariant');
const ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
class StyleSheetValidation {
/* $FlowFixMe(>=0.59.0 site=react_native_fb) This comment suppresses an error
* caught by Flow 0.59 which was not caught before. Most likely, this error
* is because an exported function parameter is missing an annotation.
* Without an annotation, these parameters are uncovered by Flow. */
static validateStyleProp(prop, style, caller) {
static validateStyleProp(prop: string, style: Object, caller: string) {
if (!__DEV__) {
return;
}
@ -36,9 +32,6 @@ class StyleSheetValidation {
var message1 = '"' + prop + '" is not a valid style property.';
var message2 = '\nValid style props: ' +
JSON.stringify(Object.keys(allStylePropTypes).sort(), null, ' ');
/* $FlowFixMe(>=0.56.0 site=react_native_oss) This comment suppresses an
* error found when Flow v0.56 was deployed. To see the error delete this
* comment and run Flow. */
styleError(message1, style, caller, message2);
}
var error = allStylePropTypes[prop](
@ -50,21 +43,11 @@ class StyleSheetValidation {
ReactPropTypesSecret,
);
if (error) {
/* $FlowFixMe(>=0.56.0 site=react_native_oss) This comment suppresses an
* error found when Flow v0.56 was deployed. To see the error delete this
* comment and run Flow. */
/* $FlowFixMe(>=0.56.0 site=react_native_fb,react_native_oss) This
* comment suppresses an error found when Flow v0.56 was deployed. To see
* the error delete this comment and run Flow. */
styleError(error.message, style, caller);
}
}
/* $FlowFixMe(>=0.59.0 site=react_native_fb) This comment suppresses an error
* caught by Flow 0.59 which was not caught before. Most likely, this error
* is because an exported function parameter is missing an annotation.
* Without an annotation, these parameters are uncovered by Flow. */
static validateStyle(name, styles) {
static validateStyle(name: string, styles: Object) {
if (!__DEV__) {
return;
}