[flow] type deprecated (#7076)
Summary: Test Plan: npm run flow Reviewers: @zpao @spicyj @gabelevi
Christopher Chedeau committed
Jun 23, 2016 at 17:46 UTC
9342c2f02f45f290a0740b6bb5d342b55a42bcf9
1 file changed
+14
-2
src/shared/utils/deprecated.js
+14
-2
@@ -7,6 +7,7 @@
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @providesModule deprecated
10
+ * @flow
11
*/
12
13
'use strict';
@@ -24,7 +25,13 @@ var warning = require('warning');
25
* @param {function} fn The function to forward on to
26
* @return {function} The function that will warn once and then call fn
27
*/
27
-function deprecated(fnName, newModule, newPackage, ctx, fn) {
28
+function deprecated<T: Function>(
29
+ fnName: string,
30
+ newModule: string,
31
+ newPackage: string,
32
+ ctx: mixed,
33
+ fn: T,
34
+): T {
35
var warned = false;
36
if (__DEV__) {
37
var newFn = function() {
@@ -47,7 +54,12 @@ function deprecated(fnName, newModule, newPackage, ctx, fn) {
54
};
55
// We need to make sure all properties of the original fn are copied over.
56
// In particular, this is needed to support PropTypes
50
- return Object.assign(newFn, fn);
57
+ Object.assign(newFn, (fn: Object));
58
+
59
+ // Flow is not smart enough to figure out that newFn is of the same type as
60
+ // fn. Since we don't want to lose out the type of the function, casting
61
+ // to any and force flow to use T.
62
+ return ((newFn: any): T);
63
}
64
65
return fn;