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

Generic 'union' shown in prop table instead of Union<X | Y> [CRA + TS] #9896

Closed
taze-fullstack opened this issue Feb 18, 2020 · 11 comments
Closed

Comments

@taze-fullstack
Copy link

Describe the bug
Prop table shows generic union on props with declared union types. [This might be the intended behavior (?) so this might be a feature request instead of a bug]

To Reproduce
Steps to reproduce the behavior:

  1. Setup CRA + TS
  2. define a component prop with a union type

Expected behavior
Prop table should say something like Union<X | Y>

Screenshots
image

Code snippets

export interface HelloProps {
  title?: string | string[];
}

export const Hello = ({title}: HelloProps) => {
  return (
    <div className="hello">
      {typeof title === 'string'
        ? title
        : title?.map((line) => {
            return (
              <span key={line} style={{display: 'block'}}>
                {line}
              </span>
            );
          })}
    </div>
  );
};

Hello.defaultProps = {
  title: 'this is the default :)',
};

export default Hello;

System:

  System:
    OS: Windows 10 10.0.18363
    CPU: (4) x64 Intel(R) Core(TM) i3-4170 CPU @ 3.70GHz   
  Binaries:
    Node: 12.14.1 - C:\Program Files\nodejs\node.EXE       
    Yarn: 1.21.1 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.13.4 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: 44.18362.449.0
@shilman
Copy link
Member

shilman commented Feb 18, 2020

I'm overhauling the props rendering and will try to get this working

@stale
Copy link

stale bot commented Mar 11, 2020

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!

@stale stale bot added the inactive label Mar 11, 2020
@shilman shilman added the todo label Mar 11, 2020
@stale stale bot removed the inactive label Mar 11, 2020
@shilman shilman added this to the 6.0.0 milestone Mar 11, 2020
@shilman shilman self-assigned this Mar 11, 2020
@bradennapier
Copy link

bradennapier commented Apr 25, 2020

Any update with this? Latest install - any types that use a union are rendered as union not the actual union values. For the most part this kind of makes this useless... it doesn't really even give us an idea of what the props can be "union" is literally the same as "any" to the viewer

@w-a-t-s-o-n
Copy link

Having the same issue. It is pretty frustrating to work around. I'm having to put the union/options in the description, which makes for a cluttered and incosistent experience for the devs consuming our component library.

@bradennapier
Copy link

You can fix this but it takes a decent amount of work. You basically need to add custom webpack config and add in the typescript info loader I forget exact name and not at computer right now

@bradennapier
Copy link

bradennapier commented Apr 29, 2020

https://github.com/strothj/react-docgen-typescript-loader

I think that is it - if you look in issues I posted how I fixed it

@bradennapier
Copy link

hipstersmoothie/storybook-addon-react-docgen#46

Never mind the info is here — even though this is a different add on - once I added the loader as I show in the issue the unions showed up for this add on as well

@shilman shilman modified the milestones: 6.0, 6.0 docs May 8, 2020
@RuneKR
Copy link

RuneKR commented May 14, 2020

This is used for docgen now right? https://www.npmjs.com/package/babel-plugin-react-docgen-typescript

@shilman shilman modified the milestones: 6.0 docs, 6.1 docs Jun 24, 2020
@shilman shilman modified the milestones: 6.1 docs, 6.2 docs Oct 13, 2020
@hipstersmoothie
Copy link
Contributor

@taze-fullstack @bradennapier @Rune-KR @derek-k-watson Has this issue persisted with storybook 6.0? The configuration for typescript docgen is a bit smarter now. If this issue has persisted could you post a reproduction repo?

@w-a-t-s-o-n
Copy link

w-a-t-s-o-n commented Oct 23, 2020 via email

@hipstersmoothie
Copy link
Contributor

Awesome! I'm going to close this issue. If the issue persists for the rest feel free to open another issue with a reproduction repo and tag me in it.

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

No branches or pull requests

6 participants