Allow passing extra arguments to proptype validators to silence deprecation warnings.

This commit is contained in:
Melvin Groenhoff
2016-10-10 16:43:42 +02:00
parent 8093f71e55
commit 4ecf3ce8aa
2 changed files with 12 additions and 1 deletions

2
react/index.d.ts vendored
View File

@@ -2282,7 +2282,7 @@ declare namespace React {
// ----------------------------------------------------------------------
interface Validator<T> {
(object: T, key: string, componentName: string): Error;
(object: T, key: string, componentName: string, ...rest: any[]): Error;
}
interface Requireable<T> extends Validator<T> {

View File

@@ -372,6 +372,17 @@ var PropTypesSpecification: React.ComponentSpec<any, any> = {
return new Error("Validation failed!");
}
return null;
},
// https://facebook.github.io/react/warnings/dont-call-proptypes.html#fixing-the-false-positive-in-third-party-proptypes
percentage: (object: any, key: string, componentName: string, ...rest: any[]): Error => {
const error = React.PropTypes.number(object, key, componentName, ...rest);
if (error) {
return error;
}
if (object[key] < 0 || object[key] > 100) {
return new Error(`prop ${key} must be between 0 and 100`);
}
return null;
}
},
render: (): React.ReactElement<any> => {