diff --git a/Libraries/Animation/POPAnimationMixin.js b/Libraries/Animation/POPAnimationMixin.js index a1ded9f95..213023290 100644 --- a/Libraries/Animation/POPAnimationMixin.js +++ b/Libraries/Animation/POPAnimationMixin.js @@ -11,14 +11,18 @@ */ 'use strict'; -var POPAnimation = require('POPAnimation'); +var POPAnimationOrNull = require('POPAnimation'); -if (!POPAnimation) { +if (!POPAnimationOrNull) { // POP animation isn't available in the OSS fork - this is a temporary // workaround to enable its availability to be determined at runtime. module.exports = (null : ?{}); } else { +// At this point, POPAnimationOrNull is guaranteed to be +// non-null. Bring it local to preserve type refinement. +var POPAnimation = POPAnimationOrNull; + var invariant = require('invariant'); var warning = require('warning'); diff --git a/Libraries/BatchedBridge/BatchedBridgedModules/POPAnimation.js b/Libraries/BatchedBridge/BatchedBridgedModules/POPAnimation.js index 2bd2ebd03..959bf2383 100644 --- a/Libraries/BatchedBridge/BatchedBridgedModules/POPAnimation.js +++ b/Libraries/BatchedBridge/BatchedBridgedModules/POPAnimation.js @@ -7,6 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule POPAnimation + * @flow */ 'use strict'; @@ -14,7 +15,7 @@ var RCTPOPAnimationManager = require('NativeModules').POPAnimationManager; if (!RCTPOPAnimationManager) { // POP animation isn't available in the OSS fork - this is a temporary // workaround to enable its availability to be determined at runtime. - module.exports = null; + module.exports = (null: ?Object); } else { var ReactPropTypes = require('ReactPropTypes'); @@ -64,6 +65,20 @@ var Types = { spring: RCTTypes.spring, }; +type Attrs = { + type?: $Enum; + property?: $Enum; + fromValue?: any; + toValue?: any; + duration?: any; + velocity?: any; + deceleration?: any; + springBounciness?: any; + dynamicsFriction?: any; + dynamicsMass?: any; + dynamicsTension?: any; +} + var POPAnimation = { Types: Types, Properties: Properties, @@ -83,11 +98,11 @@ var POPAnimation = { }), lastUsedTag: 0, - allocateTagForAnimation: function() { + allocateTagForAnimation: function(): number { return ++this.lastUsedTag; }, - createAnimation: function(typeName, attrs) { + createAnimation: function(typeName: number, attrs: Attrs): number { var tag = this.allocateTagForAnimation(); if (__DEV__) { @@ -107,35 +122,35 @@ var POPAnimation = { return tag; }, - createSpringAnimation: function(attrs) { + createSpringAnimation: function(attrs: Attrs): number { return this.createAnimation(this.Types.spring, attrs); }, - createDecayAnimation: function(attrs) { + createDecayAnimation: function(attrs: Attrs): number { return this.createAnimation(this.Types.decay, attrs); }, - createLinearAnimation: function(attrs) { + createLinearAnimation: function(attrs: Attrs): number { return this.createAnimation(this.Types.linear, attrs); }, - createEaseInAnimation: function(attrs) { + createEaseInAnimation: function(attrs: Attrs): number { return this.createAnimation(this.Types.easeIn, attrs); }, - createEaseOutAnimation: function(attrs) { + createEaseOutAnimation: function(attrs: Attrs): number { return this.createAnimation(this.Types.easeOut, attrs); }, - createEaseInEaseOutAnimation: function(attrs) { + createEaseInEaseOutAnimation: function(attrs: Attrs): number { return this.createAnimation(this.Types.easeInEaseOut, attrs); }, - addAnimation: function(nodeHandle, anim, callback) { + addAnimation: function(nodeHandle: any, anim: number, callback: Function) { RCTPOPAnimationManager.addAnimation(nodeHandle, anim, callback); }, - removeAnimation: function(nodeHandle, anim) { + removeAnimation: function(nodeHandle: any, anim: number) { RCTPOPAnimationManager.removeAnimation(nodeHandle, anim); }, }; diff --git a/Libraries/Geolocation/Geolocation.ios.js b/Libraries/Geolocation/Geolocation.ios.js index eb33fbbbe..6a022f76f 100644 --- a/Libraries/Geolocation/Geolocation.ios.js +++ b/Libraries/Geolocation/Geolocation.ios.js @@ -37,7 +37,8 @@ var Geolocation = { getCurrentPosition: function( geo_success: Function, geo_error?: Function, - geo_options?: Object) { + geo_options?: Object + ) { invariant( typeof geo_success === 'function', 'Must provide a valid geo_success callback.' diff --git a/Libraries/Image/Image.ios.js b/Libraries/Image/Image.ios.js index 1e2589723..ed857584d 100644 --- a/Libraries/Image/Image.ios.js +++ b/Libraries/Image/Image.ios.js @@ -7,6 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule Image + * @flow */ 'use strict'; @@ -106,7 +107,9 @@ var Image = React.createClass({ render: function() { var style = flattenStyle([styles.base, this.props.style]); + invariant(style, "style must be initialized"); var source = this.props.source; + invariant(source, "source must be initialized"); var isNetwork = source.uri && source.uri.match(/^https?:/); invariant( !(isNetwork && source.isStatic), diff --git a/Libraries/Image/ImageResizeMode.js b/Libraries/Image/ImageResizeMode.js index 368f4dfb8..9a7a2f954 100644 --- a/Libraries/Image/ImageResizeMode.js +++ b/Libraries/Image/ImageResizeMode.js @@ -7,6 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule ImageResizeMode + * @flow */ 'use strict'; diff --git a/Libraries/Image/ImageStylePropTypes.js b/Libraries/Image/ImageStylePropTypes.js index b48ac8653..4e361d9de 100644 --- a/Libraries/Image/ImageStylePropTypes.js +++ b/Libraries/Image/ImageStylePropTypes.js @@ -7,6 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule ImageStylePropTypes + * @flow */ 'use strict'; @@ -39,8 +40,8 @@ var unsupportedProps = Object.keys({ paddingHorizontal: null, }); -for (var key in unsupportedProps) { - delete ImageStylePropTypes[key]; +for (var i = 0; i < unsupportedProps.length; i++) { + delete ImageStylePropTypes[unsupportedProps[i]]; } module.exports = ImageStylePropTypes; diff --git a/Libraries/Interaction/InteractionManager.js b/Libraries/Interaction/InteractionManager.js index 3a104bad2..6aef690dd 100644 --- a/Libraries/Interaction/InteractionManager.js +++ b/Libraries/Interaction/InteractionManager.js @@ -7,6 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule InteractionManager + * @flow */ 'use strict'; @@ -70,7 +71,7 @@ var InteractionManager = { /** * Schedule a function to run after all interactions have completed. */ - runAfterInteractions(callback) { + runAfterInteractions(callback: Function) { invariant( typeof callback === 'function', 'Must specify a function to schedule.' @@ -82,7 +83,7 @@ var InteractionManager = { /** * Notify manager that an interaction has started. */ - createInteractionHandle() { + createInteractionHandle(): number { scheduleUpdate(); var handle = ++_inc; _addInteractionSet.add(handle); @@ -92,7 +93,7 @@ var InteractionManager = { /** * Notify manager that an interaction has completed. */ - clearInteractionHandle(handle) { + clearInteractionHandle(handle: number) { invariant( !!handle, 'Must provide a handle to clear.' diff --git a/Libraries/Interaction/InteractionMixin.js b/Libraries/Interaction/InteractionMixin.js index 633159c1f..b92120f90 100644 --- a/Libraries/Interaction/InteractionMixin.js +++ b/Libraries/Interaction/InteractionMixin.js @@ -2,6 +2,7 @@ * Copyright 2004-present Facebook. All Rights Reserved. * * @providesModule InteractionMixin + * @flow */ 'use strict'; @@ -21,7 +22,7 @@ var InteractionMixin = { } }, - _interactionMixinHandles: [], + _interactionMixinHandles: ([]: Array), createInteractionHandle: function() { var handle = InteractionManager.createInteractionHandle(); @@ -29,7 +30,7 @@ var InteractionMixin = { return handle; }, - clearInteractionHandle: function(clearHandle) { + clearInteractionHandle: function(clearHandle: number) { InteractionManager.clearInteractionHandle(clearHandle); this._interactionMixinHandles = this._interactionMixinHandles.filter( handle => handle !== clearHandle @@ -41,7 +42,7 @@ var InteractionMixin = { * * @param {function} callback */ - runAfterInteractions: function(callback) { + runAfterInteractions: function(callback: Function) { InteractionManager.runAfterInteractions(callback); }, }; diff --git a/Libraries/JavaScriptAppEngine/Initialization/ExceptionsManager.js b/Libraries/JavaScriptAppEngine/Initialization/ExceptionsManager.js index 9b2a43bcc..7dadeb5bb 100644 --- a/Libraries/JavaScriptAppEngine/Initialization/ExceptionsManager.js +++ b/Libraries/JavaScriptAppEngine/Initialization/ExceptionsManager.js @@ -7,6 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule ExceptionsManager + * @flow */ 'use strict'; @@ -18,7 +19,13 @@ var parseErrorStack = require('parseErrorStack'); var sourceMapPromise; -function handleException(e) { +type Exception = { + sourceURL: string; + line: number; + message: string; +} + +function handleException(e: Exception) { var stack = parseErrorStack(e); console.error( 'Error: ' +