mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-15 09:37:52 +08:00
Allow passing extra arguments to proptype validators to silence deprecation warnings.
This commit is contained in:
2
react/index.d.ts
vendored
2
react/index.d.ts
vendored
@@ -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> {
|
||||
|
||||
@@ -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> => {
|
||||
|
||||
Reference in New Issue
Block a user