Closed
Description
The following code snippet:
const accountInfoType = {
name: PropTypes.string,
address: PropTypes.string,
taxid: PropTypes.string,
};
AccountDetails.propTypes = {
accountInfo: PropTypes.shape(accountInfoType),
}
Throws the following error:
Cannot read property 'reduce' of undefined
TypeError: Cannot read property 'reduce' of undefined
at checkSorted ([localPath]/node_modules/eslint-plugin-react/lib/rules/sort-prop-types.js:80:19)
at CallExpression ([localPath]/node_modules/eslint-plugin-react/lib/rules/sort-prop-types.js:166:9)
at listeners.(anonymous function).forEach.listener ([localPath]/node_modules/eslint/lib/util/safe-emitter.js:47:58)
at Array.forEach (native)
at Object.emit ([localPath]/node_modules/eslint/lib/util/safe-emitter.js:47:38)
at NodeEventGenerator.applySelector ([localPath]/node_modules/eslint/lib/util/node-event-generator.js:251:26)
at NodeEventGenerator.applySelectors ([localPath]/node_modules/eslint/lib/util/node-event-generator.js:280:22)
at NodeEventGenerator.enterNode ([localPath]/node_modules/eslint/lib/util/node-event-generator.js:294:14)
at CodePathAnalyzer.enterNode ([localPath]/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:608:23)
at Traverser.enter [as _enter] ([localPath/node_modules/eslint/lib/linter.js:1006:32)
Declaring the propTypes in either of the following ways is a workaround so that it doesn't crash:
AccountDetails.propTypes = {
accountInfo: PropTypes.shape({
name: PropTypes.string,
address: PropTypes.string,
taxid: PropTypes.string,
}),
}
const accountInfoType = PropTypes.shape({
name: PropTypes.string,
address: PropTypes.string,
taxid: PropTypes.string,
});
AccountDetails.propTypes = {
accountInfo: accountInfoType,
}