storybookjs / storybook

Storybook is the industry standard workshop for building, documenting, and testing UI components in isolation
https://storybook.js.org
MIT License
84.62k stars 9.31k forks source link

[Bug]: Autodocs "union" type #25305

Open markokos01 opened 10 months ago

markokos01 commented 10 months ago

Describe the bug

I have defined some props on the component with union. For example:

export interface MyComponentProps { title: string; subtitle?: string | undefined; }

I wrote a story for my component, added "autodocs" to tags and Storybook generated controls but for prop subtitle I got type union. I expected to see string | undefined.

To Reproduce

Add prop type for example string | undefined.

System

storybook: 7.6.5 @storybook/vue3: 7.6.5 @storybook/vue3-vite: 7.6.5

Additional context

No response

larsrickert commented 8 months ago

Hey, this will be fixed with #22285

larsrickert commented 7 months ago

Fixed with #22285 in version 8

Jan-IaMe commented 7 months ago

Hi @larsrickert , this seems to be still a problem in React/Typescript/Vite. I'm using the latest version of storybook (v8.0.6).

larsrickert commented 7 months ago

@janitza-IaMe React and Vue use completely different docgen plugins :) @storybookjs/core not sure who is responsible for react?

IanVS commented 7 months ago

@janitza-IaMe the default docgen for react is now react-docgen, which is faster, but not as fully-featured. See https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#react-docgen-component-analysis-by-default to find out how to use the previous default, react-docgen-typescript instead.

Jan-IaMe commented 7 months ago

I use react-docgen and it has this problem.

IanVS commented 7 months ago

@Jan-IaMe yes that is an expected limitation of react-docgen.

asso1985 commented 2 weeks ago

I'm seeing something very similar in our Storybook recently, basically when we set props via URL we had 2 weird issues where passed prop value is not set:

1 - Placement type from floating-ui If either we redefined this as a union as such

type Placement =
  | 'top'
  | 'right'
  | 'bottom'
  | 'left'
  | 'bottom-start'
  | 'top-start'
  | 'top-end'
  | 'right-start'
  | 'right-end'
  | 'bottom-end'
  | 'left-start'
  | 'left-end';

or mark this as string problem is solved

  1. IconName We have this type
export type IconName = (typeof iconsKeys)[number];

Where iconsKeys comes from an object.

const iconsKeys = Object.keys(defaultIcons).sort();

In both cases if you either pass placement:top-start or for the other component icon:add these get ignored.

yannbf commented 5 days ago

Hey @asso1985 that looks like a different issue, would you mind writing an issue with a reproduction (using Storybook 8) so we can take a look? Thanks!