From 7612e850bc1275ca82c4063b19c3c57a13023e07 Mon Sep 17 00:00:00 2001 From: Hanu Date: Sat, 22 Apr 2017 20:26:11 +0530 Subject: [PATCH] Validating if the arguments passed to oneOf is not a function --- factoryWithTypeCheckers.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/factoryWithTypeCheckers.js b/factoryWithTypeCheckers.js index b3246b0..642d433 100644 --- a/factoryWithTypeCheckers.js +++ b/factoryWithTypeCheckers.js @@ -277,6 +277,15 @@ module.exports = function(isValidElement, throwOnDirectAccess) { return emptyFunction.thatReturnsNull; } + function isValueAFunction(value) { + return typeof value === 'function' + } + + if (expectedValues.every(isValueAFunction)) { + process.env.NODE_ENV !== 'production' ? warning(false, 'Invalid argument supplied to oneOf, expected an array of values but got an array of PropType functions. Did you mean oneOfType?') : void 0; + return emptyFunction.thatReturnsNull; + } + function validate(props, propName, componentName, location, propFullName) { var propValue = props[propName]; for (var i = 0; i < expectedValues.length; i++) {