Skip to content

Commit

Permalink
[Fix] prop-types: fix Cannot read property 'type' of undefined erro…
Browse files Browse the repository at this point in the history
…r when destructured param

 see #2805, fixes #2804, jsx-eslint/eslint-plugin-react#2805 (comment)
  • Loading branch information
minwe authored and artem0723 committed Sep 27, 2020
1 parent a069c36 commit 87e2d4f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,11 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel

## Unreleased

## Fixed
* [`prop-types`]: fix Cannot read property 'type' of undefined error when destructured param ([#2807][] @minwe)

[#2807]: https://github.com/yannickcr/eslint-plugin-react/pull/2807

## [7.21.2] - 2020.09.24

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/prop-types.js
Expand Up @@ -150,7 +150,7 @@ module.exports = {
return;
}
param.properties.forEach((property) => {
if (property.type === 'RestElement') {
if (property.type === 'RestElement' || property.type === 'ExperimentalRestProperty') {
return;
}
const type = property.value.type;
Expand Down
24 changes: 23 additions & 1 deletion tests/lib/rules/prop-types.js
Expand Up @@ -3096,7 +3096,7 @@ ruleTester.run('prop-types', rule, {
)
}
const mapDispatchToProps = (dispatch: ThunkDispatch<State, null, Action>) =>
const mapDispatchToProps = (dispatch: ThunkDispatch<State, null, Action>) =>
bindActionCreators<{prop1: ()=>void,prop2: ()=>string}>(
{ prop1: importedAction, prop2: anotherImportedAction },
dispatch,
Expand Down Expand Up @@ -6163,6 +6163,28 @@ ruleTester.run('prop-types', rule, {
errors: [{
message: "'bar' is missing in props validation"
}]
},
// fix #2804
{
code: `
import React from 'react'
const InputField = ({ type, ...restProps }) => {
return(
<input
type={type}
{...restProps}
/>
)
}
export default InputField;
`,
parser: parsers.BABEL_ESLINT,
errors: [{
message: "'type' is missing in props validation"
}]
}
])
)
Expand Down

0 comments on commit 87e2d4f

Please sign in to comment.