From 6e25d374ba811ee3b833db46835060e56d427b31 Mon Sep 17 00:00:00 2001 From: Marija Najdova Date: Thu, 14 Jan 2021 11:36:29 +0100 Subject: [PATCH] Sebastian's review --- .../material-ui-utils/src/requirePropFactory.d.ts | 4 ++-- packages/material-ui-utils/src/requirePropFactory.js | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/material-ui-utils/src/requirePropFactory.d.ts b/packages/material-ui-utils/src/requirePropFactory.d.ts index 9aca039e7be7a8..b4759fe6393271 100644 --- a/packages/material-ui-utils/src/requirePropFactory.d.ts +++ b/packages/material-ui-utils/src/requirePropFactory.d.ts @@ -1,3 +1,3 @@ -type Component = (arg: any) => any & { propTypes?: object }; +import * as React from 'react'; -export default function requirePropFactory(componentNameInError: string, Component?: Component): any; +export default function requirePropFactory(componentNameInError: string, Component?: React.ComponentType): any; diff --git a/packages/material-ui-utils/src/requirePropFactory.js b/packages/material-ui-utils/src/requirePropFactory.js index 15262e1ab9b941..dd91a063463f8d 100644 --- a/packages/material-ui-utils/src/requirePropFactory.js +++ b/packages/material-ui-utils/src/requirePropFactory.js @@ -12,12 +12,11 @@ export default function requirePropFactory(componentNameInError, Component) { ) => { const propFullNameSafe = propFullName || propName; - const defaultPropType = Component?.propTypes?.[propFullNameSafe]; - let defaultPropTypeVal = null; + const defaultTypeChecker = Component?.propTypes?.[propFullNameSafe]; + let defaultTypeCheckerResult = null; - if(defaultPropType) { - console.log("Default prop type existed"); - defaultPropTypeVal = defaultPropType(props, propName, componentName, location, propFullName) + if(defaultTypeChecker) { + defaultTypeCheckerResult = defaultTypeChecker(props, propName, componentName, location, propFullName) } if (typeof props[propName] !== 'undefined' && !props[requiredProp]) { @@ -27,7 +26,7 @@ export default function requirePropFactory(componentNameInError, Component) { ); } - return defaultPropTypeVal; + return defaultTypeCheckerResult; }; return requireProp; }