prop-types
prop-types copied to clipboard
Return value from checkPropTypes?
Is there a good reason not to return false if checkPropTypes fails any of the validations? I can't think of one myself. If no one disagrees I can do a PR.
This would be useful for those of us that want to use checkPropTypes for our own validation needs outside of React.
agreed, right now I work around it by passing this as getStack():
let error
PropTypes.checkPropTypes(...,
() => {
const error = new Error('options do not match definition')
return error.stack
}
)
if (error) throw error
EDIT:
actually that was annoying in tests - so now I mock console.error:
const t = console.error
console.error = msg => {throw new Error(msg)}
checkPropTypes(...)
console.error = t
@madcapnmckay no one seems to disagree
Would very much enjoy this, I don't see much of a reason to not provide an API to capture the errors that are being emitted to the console.
+1 Yeah I was just testing a problem using this function, and was confused why it wouldn't return some kind of information, even if just a boolean.
This seems like an obvious good change to make, but I am concerned that someone is relying on checkPropTypes returning undefined, or a falsy value - meaning, returning false is fine but returning true might break someone.
Still open? I shall take this on?