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

@hank121314 hank121314 commented Sep 23, 2020

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.

…eturnType

Fixes #2795.
@ljharb
ljharb approved these changes Sep 23, 2020
Copy link
Collaborator

@ljharb ljharb left a comment

Thanks!

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

This comment has been minimized.

@ljharb

ljharb Sep 23, 2020
Collaborator

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

This comment has been minimized.

@hank121314

hank121314 Sep 23, 2020
Author Contributor

OK! Thanks for your help.

@ljharb ljharb force-pushed the hank121314:master branch from e3d167e to 22cc878 Sep 23, 2020
@ljharb ljharb merged commit 22cc878 into yannickcr:master Sep 23, 2020
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.06%) to 97.559%
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

2 participants
You can’t perform that action at this time.