Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix]: fix prop-types Cannot read property 'type' of undefined error when destructured param #2807

Merged
merged 1 commit into from Sep 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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