prefer-exact-props
UnreleasedConfiguration
rslint.config.ts
Require React propTypes definitions to use an exact wrapper.
Rule Details
This rule reports non-empty propTypes objects that are not wrapped by a
function marked with exact: true in settings.propWrapperFunctions. Empty
objects are allowed.
Configure an exact wrapper in the shared React settings:
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Differences from ESLint
- Only assignments to
.propTypesare checked. Other reads are ignored; eslint-plugin-react 7.37.5 may report them or throw while evaluating them. - Class fields are checked only when they are static and their runtime name is
propTypes. Instance fields,#privatefields, and TypeScriptpropsfields are ignored. - Computed member names are checked only when written as a string or static
template literal, such as
Component['propTypes']. Variables used as keys are ignored. - A
propTypesvalue referenced through a variable is checked only when the variable is a directly initializedconst. For object literals, every value reference must be anotherpropTypesassignment; property mutations, escapes, other reads, mutable bindings, and destructured bindings are treated as unknown.