New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.set and .setOf #191
base: main
Are you sure you want to change the base?
.set and .setOf #191
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about Map?
function createSetTypeChecker(expectedType) { | ||
function validate(props, propName, componentName, location, propFullName, secret) { | ||
var propValue = props[propName]; | ||
if (!(propValue instanceof Set)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed, this should module-level-cache the getter for Set.prototype.size, call-bind it, and invoke it here.
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside setOf.'); | ||
} | ||
var propValue = props[propName]; | ||
if (!(propValue instanceof Set)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also here
@@ -505,6 +553,8 @@ module.exports = function(isValidElement, throwOnDirectAccess) { | |||
return 'date'; | |||
} else if (propValue instanceof RegExp) { | |||
return 'regexp'; | |||
} else if (propValue instanceof Set) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here
An implementation for
.set
and.setOf
. Please hit me with your feedback, thoughts, and ideas.I can implement
.map
and.mapOf
in this PR as well.@ljharb mentioned that
instanceof Set
does not work everywhere. Perhaps that has to be fixed.