From ee0fd76b1ac8258cdc8daaed11b4e8877a088f28 Mon Sep 17 00:00:00 2001 From: jethro larson Date: Mon, 7 May 2018 19:43:25 -0700 Subject: [PATCH] Add checkPropTypes definition to @types/prop-types I used the jsdoc as guide in https://github.com/facebook/prop-types/blob/master/checkPropTypes.js --- types/prop-types/index.d.ts | 12 ++++++++++++ types/prop-types/prop-types-tests.ts | 2 ++ 2 files changed, 14 insertions(+) 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');