The Wayback Machine - https://web.archive.org/web/20200527134253/https://github.com/teambit/bit/issues/2486
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

support interfaces in automatic docs #2486

Open
KutnerUri opened this issue Mar 24, 2020 · 4 comments
Open

support interfaces in automatic docs #2486

KutnerUri opened this issue Mar 24, 2020 · 4 comments

Comments

@KutnerUri
Copy link
Collaborator

@KutnerUri KutnerUri commented Mar 24, 2020

I have a component with types and jsdocs:

export type ButtonProps = {
  /**
   * explicitly toggle loader on and off
   */
  loading?: boolean;
} & React.ButtonHTMLAttributes<HTMLButtonElement>;

/**
 * Base button, with very basic styles. Accepts all parameters of native html button.
 * If onClick returns a promise, BaseButton will show a loader automatically, until the promise is resolved or rejected.
 */
export default class Button extends Component<ButtonProps> {
  render() {
    const { loading, ...rest } = this.props;

    const content = loading ? loader : children;

    return <button {...rest}>{content}</button>;
  }
}

I get these docs:

┌────────────────────┬──────────────────────────────────────────────────┐
  │ Name               │ Button                                           │
  ├────────────────────┼──────────────────────────────────────────────────┤
  │ Description        │ Base button, with very basic styles. Accepts all │
  │                    │ parameters of native html button.                │
  │                    │ If onClick returns a promise, BaseButton will    │
  │                    │ show a loader automatically, until the promise   │
  │                    │ is resolved or rejected.                         │
  ├────────────────────┼──────────────────────────────────────────────────┤
  │ Properties         │ (loader: ReactNode, loading: boolean)            │
  └────────────────────┴──────────────────────────────────────────────────┘

When I change the type to be an interface, Bit no longer identifies the props as a type:

export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
	/**
	 * explicitly toggle loader on and off
	 */
	loading?: boolean;
};
┌────────────────────┬──────────────────────────────────────────────────┐
  │ Name               │                                                  │
  ├────────────────────┼──────────────────────────────────────────────────┤
  │ Description        │ explicitly toggle loader on and off              │
  └────────────────────┴──────────────────────────────────────────────────┘
  ┌────────────────────┬──────────────────────────────────────────────────┐
  │ Name               │                                                  │
  ├────────────────────┼──────────────────────────────────────────────────┤
  │ Description        │ Base button, with very basic styles. Accepts all │
  │                    │ parameters of native html button.                │
  │                    │ If onClick returns a promise, BaseButton will    │
  │                    │ show a loader automatically, until the promise   │
  │                    │ is resolved or rejected.                         │
  └────────────────────┴──────────────────────────────────────────────────┘

Please support interface syntax in automatic docs. 😃

Specifications

bit version: 14.7.6

@davidfirst
Copy link
Member

@davidfirst davidfirst commented Apr 10, 2020

Thanks @KutnerUri for reporting this.
I have a feeling that this is the exact same issue you had with the "private" / "public" syntax.
For some reason, react-docgen doesn't like TS syntax when it's running programmatically.
I'll try to take a second look as soon as I can.

@KutnerUri
Copy link
Collaborator Author

@KutnerUri KutnerUri commented Apr 12, 2020

Could it have something to do with the babel configuration?
It might be better to collect docs from the dists, but some docs might be lost along the way.

@davidfirst
Copy link
Member

@davidfirst davidfirst commented Apr 15, 2020

@KutnerUri , Yes!
I don't have the time to try it now and it'd be great if you could try it yourself.
It's in react-parser.ts file:

const componentsInfo = reactDocs.parse(data, reactDocs.resolver.findAllComponentDefinitions, undefined, {
      configFile: false
    });

According to the docs, the syntax is parse(source [, resolver [, handlers [, options]]]).
The options can get parserOptions, which is babel options.
So, there is a good chance that if you replace the above with:

const componentsInfo = reactDocs.parse(data, reactDocs.resolver.findAllComponentDefinitions, undefined, {
      configFile: false,
     parserOptions: { plugins: ['typescript', 'jsx'] }
    });

It'll work.

@KutnerUri
Copy link
Collaborator Author

@KutnerUri KutnerUri commented May 21, 2020

this will probably be resolved by PR #2690

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.