default-props-match-prop-types
UnreleasedConfiguration
Ensures that each default prop has a corresponding, non-required prop declaration.
Rule Details
A default for an undeclared prop can indicate a misspelling or an incomplete refactor. A default for a required prop can indicate that the prop should be optional.
The rule checks defaultProps assignments, static class fields and getters, and getDefaultProps in createReactClass components. Prop declarations can use runtime propTypes or TypeScript annotations.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Components without any known prop declarations are ignored. Default objects containing spreads or unresolved external defaults are also ignored.
Options
allowRequiredDefaults
A boolean, defaulting to false. When true, required props may have defaults; defaults for undeclared props are still reported.
Differences from ESLint
- Quoted, numeric, and static computed keys compare by their value, including
C['defaultProps']andC.defaultProps['name']; ESLint may skip them or reportundefined. - Parenthesized and TypeScript-wrapped receivers are recognized, including
(C as any).defaultProps; ESLint ignores TypeScript-wrapped receivers. - Typed props parameters may have any name, and type aliases follow lexical scope; ESLint limits parameter detection and searches top-level type declarations.
- Ambient
React.FCdeclarations are recognized consistently with and without a typed Program; ESLint ignores them without a local React import. - Configured React pragma aliases contribute
forwardRefgeneric props, while ESLint only recognizes the literalReact.forwardRefreceiver. - Class fields follow React's instance/static contract: typed
propsmust be an instance field, while runtimepropTypesmust be static. - Unknown prop declarations, including spreads and imported types, suppress missing-type reports. Known required props remain checked; ESLint can report props hidden by an unknown declaration as missing.
- Dynamic default keys are ignored when their names cannot be determined, instead of being compared as source text.