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, propTypes: handle React.* TypeScript types #3049

Merged
merged 1 commit into from Aug 25, 2021

Conversation

vedadeepta
Copy link
Contributor

@vedadeepta vedadeepta commented Aug 25, 2021

Fixes #3045 and related issues (#2786)

Implements logic discussed in this comment: #2777 (comment)

@codecov-commenter
Copy link

codecov-commenter commented Aug 25, 2021

Codecov Report

Merging #3049 (a315a2f) into master (3d23496) will decrease coverage by 0.01%.
The diff coverage is 92.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3049      +/-   ##
==========================================
- Coverage   97.42%   97.40%   -0.02%     
==========================================
  Files         111      111              
  Lines        7452     7472      +20     
  Branches     2726     2736      +10     
==========================================
+ Hits         7260     7278      +18     
- Misses        192      194       +2     
Impacted Files Coverage Δ
lib/util/annotations.js 90.00% <ø> (ø)
lib/util/propTypes.js 96.95% <92.85%> (-0.26%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3d23496...a315a2f. Read the comment docs.

@vedadeepta

This comment has been minimized.

@vedadeepta vedadeepta force-pushed the 3045-handle-ReactFC-propTypes branch from a1769e1 to a315a2f Compare August 25, 2021 13:51
@vedadeepta vedadeepta changed the title [Fix]: typescript, prop-types, propTypes: handle React.* types [Fix]: typescript, prop-types, propTypes: handle generic types Aug 25, 2021
@ljharb ljharb force-pushed the 3045-handle-ReactFC-propTypes branch from a315a2f to d74a7d8 Compare August 25, 2021 16:10
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, looks great

@ljharb ljharb changed the title [Fix]: typescript, prop-types, propTypes: handle generic types [Fix] prop-types, propTypes: handle React.* TypeScript types Aug 25, 2021
@ljharb
Copy link
Member

ljharb commented Aug 25, 2021

Does this solve #2777 as well?

@vedadeepta
Copy link
Contributor Author

vedadeepta commented Aug 25, 2021

Does this solve #2777 as well?

Nope, it will show an error for code like this

interface Props {
    posts: string[];
}
const Home: NextPage<Props> = ({ posts }) => {
  return <span>jsx</span>
}

because NextPage is not in our allowedGenericTypes so line 945 will block the construction of declaredPropTypes from TS interface definition.

If we want this case to be handled we need to make allowedGenericTypes configurable by the user, or maybe there is a much cleaner way to solve this - I'm not really sure at the moment.

@ljharb
Copy link
Member

ljharb commented Aug 25, 2021

ok - we can look into that in a followup. it'd be great to allow all generic types and actually respect what they declare.

@vedadeepta
Copy link
Contributor Author

I actually forgot to handle the FunctionComponent<Props> or FC<Props> case. Will do it in a follow up PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

[Bug] Enable Plugin to Properly Acknowledge Props Provided Via React.FC
3 participants