diff --git a/types/prop-types/index.d.ts b/types/prop-types/index.d.ts index ebeef159b0..67146e6cc7 100644 --- a/types/prop-types/index.d.ts +++ b/types/prop-types/index.d.ts @@ -28,3 +28,15 @@ export function oneOfType(types: Array>): Requireable; export function arrayOf(type: Validator): Requireable; export function objectOf(type: Validator): Requireable; export function shape(type: ValidationMap): Requireable; + +/** + * Assert that the values match with the type specs. + * Error messages are memorized and will only be shown once. + * + * @param typeSpecs Map of name to a ReactPropType + * @param values Runtime values that need to be type-checked + * @param location e.g. "prop", "context", "child context" + * @param componentName Name of the component for error messages. + * @param getStack Returns the component stack. + */ +export function checkPropTypes(typeSpecs: any, values: any, location: string, componentName: string, getStack?: () => any): void; diff --git a/types/prop-types/prop-types-tests.ts b/types/prop-types/prop-types-tests.ts index 238a22b1ef..4d5a939b6e 100644 --- a/types/prop-types/prop-types-tests.ts +++ b/types/prop-types/prop-types-tests.ts @@ -25,3 +25,5 @@ const propTypes: PropTypes.ValidationMap = { node: PropTypes.node.isRequired, element: PropTypes.element.isRequired }; + +PropTypes.checkPropTypes({xs: PropTypes.array}, {xs: []}, 'location', 'componentName');