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] prop-types: Should handle CallExpression in ReturnType #2802

Merged
merged 1 commit into from Sep 23, 2020

Conversation

hank121314
Copy link
Contributor

Summary

This pr fixes: #2795.

This pr handle CallExpression which come from two places.

  1. From ReturnType function body:
    For example:
const mapDispatchToProps = (dispatch: ThunkDispatch<State, null, Action>) => 
  bindActionCreators<{props1: ()=>void,props2: ()=>string}>(
    { prop1: importedAction, prop2: anotherImportedAction },
    dispatch,
)
  1. From RerturnType function return object spread properties:
    For example:
const mapDispatchToProps = (dispatch: ThunkDispatch<State, null, Action>) => ({
  ...bindActionCreators<{prop1: ()=>void,prop2: ()=>string}>(
    { prop1: importedAction, prop2: anotherImportedAction },
    dispatch,
  ),
})

If user give us typeParameters of CallExpression, eslint will do prop-types check.
If user did not give us, eslint will ignore the prop-types check since we cannot get the return value.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@@ -6765,7 +6848,38 @@ ruleTester.run('no-unused-prop-types', rule, {
}, {
message: '\'username\' PropType is defined but prop is never used'
}]
}])
}]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the below TS tests need to be inside this call. I'll fix this when i rebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK! Thanks for your help.

@ljharb ljharb merged commit 22cc878 into jsx-eslint:master Sep 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

TypeError: Cannot read property 'type' of undefined
2 participants