Skip to content

Commit

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

 see jsx-eslint#2805, jsx-eslint#2804, jsx-eslint#2805 (comment)
  • Loading branch information
minwe committed Sep 27, 2020
1 parent 4589522 commit d75c555
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
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 d75c555

Please sign in to comment.