@@ -66,7 +66,7 @@ export const AddThemeStylesValidator = (
6666 *
6767 * SEE: https://github.com/reactjs/prop-types
6868 */
69- const fnExactValidator = (
69+ const fnNoExtraPropsValidator = (
7070 // prop-types Object supplied by the user. i.e {lorem: PropTypes.string}
7171 propsObject : PropsTypeObjectType ,
7272 // prop-values Object supplied by the user. i.e {lorem: 'ipsum'}
@@ -90,29 +90,34 @@ const fnExactValidator = (
9090
9191/**
9292 * Adds a 'custom validator' function to `obj`; this function makes sure that any
93- * 'prop' passed by the user at runtime exists in `obj`, otherwise it throws an Error.
94- * `obj` is a 'props' object, the one you would assign to `SomeComponent.propTypes`
93+ * 'prop' passed by the user at runtime exists as a key in `obj`, otherwise it throws
94+ * an Error. `obj` is a 'props' object, the one you would assign to `SomeComponent.propTypes`
9595 * or pass to `PropTypes.checkPropTypes()`. i.e {lorem: PropTypes.string}
9696 *
97- * We use bind() to make a new `fnExactValidator ` function with the first argument
97+ * We use bind() to make a new `fnNoExtraPropsValidator ` function with the first argument
9898 * set as: `obj`. We need to do this because `prop-types` doesn't pass this object
99- * to 'custom validator' functions such as `fnExactValidator`.
99+ * to 'custom validator' functions such as `fnNoExtraPropsValidator`.
100+ *
101+ * This type of validation is NOT the runtime equivalent to Flow's 'exact object
102+ * types', since we don't check if any required `prop-types` props have been supplied
103+ * or not, relying on the user to have specified an appropriate `isRequired` prop-type
104+ * for those.
100105 *
101- * This type of validation is the runtime equivalent to Flow's 'exact object types'.
102106 * SEE: https://flow.org/en/docs/types/objects/#toc-exact-object-types
103107 */
104108// eslint-disable-next-line import/prefer-default-export, max-len
105- export const AddExactValidator = (
109+ export const AddNoExtraPropsValidator = (
106110 obj : PropsTypeObjectType ,
107111) : PropsTypeObjectType => {
108- const validatorKeyName = '__exact__ '
112+ const validatorKeyName = '__no__extra__props__validator___ '
109113 if ( Object . prototype . hasOwnProperty . call ( obj , validatorKeyName ) ) {
110- // TODO: print a message or throw when not in production?
111- return obj // The custom validator is already 'installed'.
114+ // The custom validator is already 'installed', or the user has managed to
115+ // somehow use `validatorKeyName`.
116+ return obj
112117 }
113118
114119 return {
115120 ...obj ,
116- [ validatorKeyName ] : fnExactValidator . bind ( this , obj ) ,
121+ [ validatorKeyName ] : fnNoExtraPropsValidator . bind ( this , obj ) ,
117122 }
118123}
0 commit comments