From 24cf5c7a5e9566d1122eb1193df3f31d79525326 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Thu, 23 Jun 2016 17:46:24 +0200 Subject: [PATCH] [flow] type deprecated (#7076) Summary: Test Plan: npm run flow Reviewers: @zpao @spicyj @gabelevi (cherry picked from commit 9342c2f02f45f290a0740b6bb5d342b55a42bcf9) --- src/shared/utils/deprecated.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/shared/utils/deprecated.js b/src/shared/utils/deprecated.js index fd8edec6e4..e8cc2e1539 100644 --- a/src/shared/utils/deprecated.js +++ b/src/shared/utils/deprecated.js @@ -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( + 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;