[flow] type deprecated (#7076)

Summary:

Test Plan:
npm run flow

Reviewers: @zpao @spicyj @gabelevi
(cherry picked from commit 9342c2f02f)
This commit is contained in:
Christopher Chedeau
2016-07-08 10:48:56 -07:00
committed by Paul O’Shannessy
parent 8ea1ee14d5
commit 24cf5c7a5e
+14 -2
View File
@@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule deprecated
* @flow
*/
'use strict';
@@ -24,7 +25,13 @@ var warning = require('warning');
* @param {function} fn The function to forward on to
* @return {function} The function that will warn once and then call fn
*/
function deprecated(fnName, newModule, newPackage, ctx, fn) {
function deprecated<T: Function>(
fnName: string,
newModule: string,
newPackage: string,
ctx: mixed,
fn: T,
): T {
var warned = false;
if (__DEV__) {
var newFn = function() {
@@ -47,7 +54,12 @@ function deprecated(fnName, newModule, newPackage, ctx, fn) {
};
// We need to make sure all properties of the original fn are copied over.
// In particular, this is needed to support PropTypes
return Object.assign(newFn, fn);
Object.assign(newFn, (fn: Object));
// Flow is not smart enough to figure out that newFn is of the same type as
// fn. Since we don't want to lose out the type of the function, casting
// to any and force flow to use T.
return ((newFn: any): T);
}
return fn;