Repository navigation
Conversation
👷 Deploy request for react-docgen pending review.Visit the deploys page to approve it
|
🦋 Changeset detectedLatest commit: 763148b The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #897.
What was wrong
When a component variable is typed with a function type instead of
React.FC, react-docgen found no props:What this changes
findAssignedVariableTypeingetTypeFromReactComponent.tsalready reads the props type fromReact.FC<Props>and friends. If the annotation is not one of those, it now takes the type of the first parameter of:const C: (props: Props) => X = ...) or through a type aliasinterface Fn { (props: Props): X })type Component<P> = (props: P) => Xused asComponent<Props>). Here the type argument is used.Two behaviours follow the existing
React.FCpath, and I kept them the same:const C: React.FC<A> = (props: B) => ...today.Tests
codeTypeHandler-test.ts. Without the change ingetTypeFromReactComponent.ts, the 6 positive cases fail. The 7th checks that a type which is not a function type still gives no props.pnpm testpasses everywhere. react-docgen has 1521 tests, and the core, babel, typescript, hermes and cli packages pass too.pnpm lint,tsc --noEmitand Prettier are clean on the changed files.parse():Fn1and the call-signature variant now listfoo, where both used to givenull.