-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
doc update for typescript props config #1514
Conversation
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.
Thanks!
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.
Looks like I wrote a comment here a long time ago and didn't send it ;-/
docs/Thirdparties.md
Outdated
@@ -54,6 +54,20 @@ module.exports = { | |||
|
|||
Please see our [examples](https://github.com/styleguidist/react-styleguidist/tree/master/examples) and refer to [react-docgen](https://github.com/reactjs/react-docgen) documentation for more information about what types of syntax are supported. | |||
|
|||
But if components are written with typescript and extending other components (which are also written using typescript), You may use `react-docgen-typescript` module for fetching extended component prop definitions automatically. Follow the steps to configure same. |
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.
Still confusing for me: what exactly isn't working — extension or import from another file? A code example would be very good here too.
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.
context was set in before para. Example of how it doesn't work probably unrelated.
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.
It is very much "related". I still don't understand what's the problem exactly, and, looking at the comments, you probably don't understand either. We can't expect users to understand it.
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.
Have done the changes. Sorry for resolving bit late.
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.
Thanks, but it still doesn't answer my question: what exactly isn't working — importing any component or specifically from node_modules
. From what you've said before I understood it's the former, but from the text it looks like the latter.
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.
actually issue seems to be from both any component and node_modules. React doc gen doesn't support. But with react-docgen-typescript
, both will work.
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.
So something like this also won't work?
import Button from './AnotherButton'
export default Button
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.
My bad. I was initially discussing with what I am aware of. So I spent sometime around this. So here is a detailed info.
First it's surely not working with extended third party components.
Example: Please check #1508 (comment)
Second, components which are extended from internal ones are working fine.
But I was checking wrong example which didn't work.
This one didn't work most probably coz it is using style component declaration which is not a standard React component creating pattern.
Now checked above directly using react-docgen-typescript
as well. Apart from displaying the 3 declared props, it also displayed props of styled component which is again 3rd party component.
There are lot of ifs/buts around this. But what I can summarize from this, is to inform user that for fetching props of third party components only, we should recommend users to use react-docgen-typescript
.
Let know your thoughts around this.
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.
First it's surely not working with extended third party components.
That's clear now, but let's not call then "third-party", since it might be ambiguous. "Components rexeported from node_modules" would be more precise.
Second, components which are extended from internal ones are working fine.
Example: https://github.com/styleguidist/react-styleguidist/tree/11/examples/styled-components/src/components/Heading
This component doesn't extend another component.
Now checked above directly using react-docgen-typescript as well. Apart from displaying the 3 declared props, it also displayed props of styled component which is again 3rd party component.
There's a way to filter props in react-docgen-typescript:
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.
This component doesn't extend another component.
index.ts
of Heading Component is importing component from Heading.tsx
. So something like below will also work.
import Button from './AnotherButton'
export default Button
Have done the changes as suggested by you.
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.
I thinks something like this may work.
docs/Thirdparties.md
Outdated
@@ -54,6 +54,28 @@ module.exports = { | |||
|
|||
Please see our [examples](https://github.com/styleguidist/react-styleguidist/tree/master/examples) and refer to [react-docgen](https://github.com/reactjs/react-docgen) documentation for more information about what types of syntax are supported. | |||
|
|||
But while writing components using typescript and re-exporting a component from node_modules, You can still be able to fetch prop definitions of the parent component using `react-docgen-typescript`. |
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.
But while writing components using typescript and re-exporting a component from node_modules, You can still be able to fetch prop definitions of the parent component using `react-docgen-typescript`. | |
While Styleguidist supports TypeScript out of the box, thanks to `react-docgen`, this support is limited. Consider this example:``` |
docs/Thirdparties.md
Outdated
export default Button | ||
``` | ||
|
||
In the above example, we were trying to extend a component which is from node_modules. Now if we want prop definitions of the parent component, `react-docgen` won't be able to fetch them. For same you can setup `react-docgen-typescript` with `styleguidist` by following below steps. |
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.
In the above example, we were trying to extend a component which is from node_modules. Now if we want prop definitions of the parent component, `react-docgen` won't be able to fetch them. For same you can setup `react-docgen-typescript` with `styleguidist` by following below steps. | |
Here we’re reexporting a third-party component from `node_modules`. Styleguidist won’t be able to render prop types of this component, unless we’re using `react-docgen-typescript`: |
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.
Yep. Suggestions totally right. Updated with suggestions.
Thanks, merging! |
🎉 This PR is included in version 11.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
documentation update for #1508