mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[flow] type deprecated (#7076)
Summary: Test Plan: npm run flow Reviewers: @zpao @spicyj @gabelevi
This commit is contained in:
committed by
GitHub
parent
416b5ef173
commit
9342c2f02f
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user