-
-
Notifications
You must be signed in to change notification settings - Fork 9.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
Optional values get appended undefined in Addon-docs prop table when using typescript #9395
Comments
Required props have a red star next to them. Optional props don't. In that sense the |
Yes, it's definitely correct that it can be undefined... |
I think is both correct and redundant. Maybe more redundant than correct since when you add more props you get something like this. Besides looking buggy is pretty useless because you don't need to know that <Button color={undefined} /> That being said, a way to filter the props would be nice however, both the rows that are being displayed and the contents. |
@papeloto that's not strictly true. Users may opt to do something like this: <Button color={() => someThing ? 'red' : undefined} /> But I also agree that we could get rid of undefined. Again, we'd definitely welcome a PR here if you're interested? If not, I can take a look this week. I'm not sure if this work would be better as a part of Docs or the docgen loader (@shilman - what do you think)? |
Oops, I didn't consider that case. |
NP, I'll talk to @shilman about it. |
I agree that "undefined" is redundant. I planned to remove it, some of the code is already in SB https://github.com/storybookjs/storybook/blob/next/addons/docs/src/lib/docgen/typeScript/createType.ts Haven't had the time yet to plug in in the transformation pipeline. (when we switch to react-docgen 5.* to handle TypeScript it will be plugged automatically) |
Cool let's plan to just deal with it in the |
@patricklafrance check your discord messages 😘 |
This has been solved so far, so thank you so much and great work! ❤️ |
@vimtor Where has this been solved? I still have this issue |
@AsasInnab have you found the solution? I'm having this same issue |
I'm having the same issue. Storybook v6.3.2. My main.js looks like:
|
I think beyond the aesthetic concerns it's can cause components to render incorrectly, see the following example (v6.4.8): Foo.tsx import React from "react";
interface Props {
myProp?: "a" | "b";
}
const Foo: React.FC<Props> = ({ myProp = "a" }) => {
console.log(myProp, typeof myProp);
if (myProp === "a") return <>A</>;
return <>B</>;
};
export default Foo;
export type { Props }; Foo.stories.tsx import { ComponentStory, ComponentMeta } from "@storybook/react";
import Foo from "./Foo";
export default {
title: "Components/Foo",
component: Foo,
} as ComponentMeta<typeof Foo>;
const Template: ComponentStory<typeof Foo> = (args) => <Foo {...args} />;
export const A = Template.bind({});
A.args = { myProp: "a" };
export const B = Template.bind({});
B.args = { myProp: "b" };
export const WithDefaultProps = Template.bind({}); In this case |
@MerlinMason what version are you on? pretty sure this got fixed at some point |
@shilman this was v6.4.8 |
Describe the bug
When using
addon:docs
prop table for React tsx components optional props marked with?
in typescript get appendedundefined
in the table.To Reproduce
yarn storybook
and see the result.Expected behavior
Props marked as optional don't need the
undefined
.System:
System:
OS: Linux 5.0 Ubuntu 18.04.3 LTS (Bionic Beaver)
CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
Binaries:
Node: 10.18.0 - /usr/bin/node
Yarn: 1.21.1 - /usr/bin/yarn
npm: 6.13.4 - /usr/bin/npm
Browsers:
Chrome: 79.0.3945.88
Firefox: 71.0
npmPackages:
@storybook/cli: ^5.3.0 => 5.3.0
The text was updated successfully, but these errors were encountered: