-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
feat(gatsby-transformer-react-docgen): fallback to TypeScript or Flow #15202
Conversation
The key `type` on the `property` is undefined when parsing `typescript` files. Example TypeScript file that caused this issue: ```tsx import React, { ReactNode } from "react" export type Props = { anyThing: string /** * * @type {ReactNode} * @memberof Props */ children: ReactNode } export default function Anything({ }: Props) { return <div>content</div> } ``` That was because the react-docgen parser sets the `flowType` key instead of `type` when no JSDoc is written.
This hole thing gets fixed in It is possible to use it in your current projects with: "resolutions": {
"react-docgen": "5.0.0-beta.1"
} Closing this PR - since this fix is a suitable workaround |
correction, its not fixed when you use documentation in code. |
I parsed this test interface: export interface Props {
/**
* Perfectly Documented
*
* @type {string}
* @memberof Props
*/
color: string
/**
* Bad Documented
* @memberof Props
*/
children: ReactNode
// Nearly not Documented
type: string
notDocument: number | any
} ResultsGood Doc/**
* Perfectly Documented
*
* @type {string}
* @memberof Props
*/
color: string Parsed Ouput
{
"tsType": {
"name": "string"
},
"type": {
"name": "string"
},
"name": "color",
"required": true,
"docblock": "Perfectly Documented\n\n@type {string}\n@memberof Props",
"description": {
"text": "Perfectly Documented"
},
"flowType": null,
"doclets": [
{
"tag": "type",
"value": "{string}"
},
{
"tag": "memberof",
"value": "Props"
}
]
} Bad Doc/**
* Bad Documented
* @memberof Props
*/
children: ReactNode Result
{
"tsType": {
"name": "ReactNode"
},
"type": null,
"name": "children",
"required": true,
"docblock": "Bad Documented\n@memberof Props",
"description": {
"text": "Bad Documented"
},
"flowType": null,
"doclets": [
{
"tag": "memberof",
"value": "Props"
}
]
} since that i guess the priority of defining
|
Could you add a new test for this? Thanks for the contribution! |
Hey @KyleAMathews i added some tests to the use case, actually found a little bug. |
that's awesome! :) I was going to look into this one, thanks for getting back to us! Is it possible to test unions with tsType & flowType too? It seems like they are handled a bit different than prop types. |
Hey @wardpeet! Thanks for answering, i actually tried out many constructions with typeScript now and thought it would be useful to have some doclets tests too, i added them. My working examples for the type tests were: /**
* @type {React.Component<Props>}
*/
component: React.Component<Props>
/**
* @type {(number | any)}
*/
union: number | any I looked for the default behauvior thats implemented, found a little bug in the doclet parsing when this string is converterted: |
Thank you. Any chance you can create a small reproduction on how to test this PR? |
I have a current project where i use it: You have to use I changed this package (transformer-react-docgen) manually, when you update it to this PR you can just The parsed file is |
Since this depends on behaviour in the v5 beta, I’ll merge this in after #16094 is published (major version with breaking change and upgraded to v5) which will likely be later today |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to go in now! Thank you so much @Sly321 👍
Holy buckets, @Sly321 — we just merged your PR to Gatsby! 💪💜 Gatsby is built by awesome people like you. Let us say “thanks” in two ways:
If there’s anything we can do to help, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’. Thanks again! |
The key
type
on theproperty
is undefined when parsingtypescript
files.Example TypeScript file that caused this issue:
That was because the react-docgen parser sets the
flowType
key instead oftype
when no JSDoc is written.Error is: