Registry / type-stubs / prop-types-extra

prop-types-extra

JSON →
library1.1.1jsnpmunverified

prop-types-extra is a utility library designed to augment React's prop-validation capabilities by providing an extended set of PropTypes. It builds upon the foundational `prop-types` package, offering specialized validators that address common and complex validation scenarios in React component development. Key validators include `all`, which enables combining multiple validation rules; `componentOrElement`, for validating props expecting either a React component or a DOM element reference; `deprecated`, a utility to log deprecation warnings for specific props; `elementType`, for ensuring a prop is a valid React element type (e.g., a string for a DOM element or a component constructor); and `isRequiredForA11y`, which enforces accessibility requirements. The package is currently at version 1.1.1. As a supplementary tool for `prop-types`, its release cadence is typically stable, with updates driven primarily by React's evolution or specific bug fixes rather than frequent feature additions. It differentiates itself by providing ready-to-use, advanced validation patterns, thereby simplifying the creation of robust and semantically correct React components.

type-stubsweb-framework
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Preferred for general use. The CommonJS `require` syntax is less modern and may not be supported in all build environments.

import { elementType } from 'prop-types-extra';

Use this direct path import to cherry-pick individual validators and optimize bundle size. Importing a named export from the `lib/` path is incorrect.

import elementType from 'prop-types-extra/lib/elementType';

Standard named import for the `all` validator. The CommonJS `require` syntax is less modern.

import { all } from 'prop-types-extra';

Standard named import for the `deprecated` validator. Direct path import is `import deprecated from 'prop-types-extra/lib/deprecated';`.

import { deprecated } from 'prop-types-extra';

Demonstrates the use of the `all` validator to combine standard PropTypes with a custom semantic validation function, showing how to enforce conditional prop dependencies for robust component usage.

import React from 'react'; import PropTypes from 'prop-types'; import { all } from 'prop-types-extra'; interface MyComponentProps { vertical: boolean; block: boolean; } const MyComponent: React.FC<MyComponentProps> = ({ vertical, block }) => { return ( <div style={{ display: block ? 'block' : 'inline', flexDirection: vertical ? 'column' : 'row' }}> My Component Content </div> ); }; MyComponent.propTypes = { vertical: PropTypes.bool.isRequired, block: all( PropTypes.bool.isRequired, ({ block, vertical }: MyComponentProps) => ( block && !vertical ? new Error('`block` requires `vertical` to be set to have any effect') : null ), ) as PropTypes.Validator<boolean>, // Type cast for custom validator }; // Example usage: // In a React application, this component would be rendered: // import ReactDOM from 'react-dom'; // const rootElement = document.getElementById('root'); // ReactDOM.render(<MyComponent vertical={true} block={true} />, rootElement); // <MyComponent vertical={false} block={true} /> // Will log a propTypes warning in development
Debug
Known footguns
gotchaImporting `prop-types-extra` directly imports all validators, which can increase bundle size.
gotchaThis library extends the standard `prop-types` library and does not replace it. You still need to import `PropTypes` from `prop-types` (or `React.PropTypes` in very old React versions) for basic validations like `PropTypes.string`.
gotchaThis package is designed for environments where `PropTypes` has been extracted into the standalone `prop-types` package (React 15.5.0 and later). Using it with significantly older React versions (pre-15.5.0) might lead to incompatibility or `PropTypes` not being correctly resolved.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
17 hits · last 30 days
gptbot
4
ahrefsbot
4
dotbot
3
script
1
bytedance
1
Resources