react-docgen-typescript-loader
react-docgen-typescript-loader copied to clipboard
Imported `enum` types are displayed with propType "any"
If a component uses a prop of an enum that is imported from another file, the propType will be shown as any.
This will correctly label the color property as propType Color:
// SomeComponent.tsx
import * as React from 'react';
export enum Color {
PRIMARY = 'primary',
SECONDARY = 'secondary',
COMPLEMENTARY = 'complementary',
TERTIARY = 'tertiary',
ANCILLARY = 'ancillary',
}
interface Props {
/** The color */
color?: Color;
}
const SomeComponent: React.SFC<Props> = (props) => {
return 'test';
};
export default SomeComponent;
This will incorrectly label the color property as propType any:
// Color.ts
export enum Color {
PRIMARY = 'primary',
SECONDARY = 'secondary',
COMPLEMENTARY = 'complementary',
TERTIARY = 'tertiary',
ANCILLARY = 'ancillary',
}
// SomeComponent.tsx
import * as React from 'react';
import { Color } from './Color';
interface Props {
/** The color */
color?: Color;
}
const SomeComponent: React.SFC<Props> = (props) => {
return 'test';
};
export default SomeComponent;
Thank you for the issue report! I will investigate this tomorrow (Sunday).
Thanks @strothj !
Hello,
I've been trying to reproduce this issue but haven't had success. Can you upload a minimal example repo? Also are you sure you have the latest version installed, there was an update that bumped the package react-docgen-typescript which handles the parsing.
I've added a branch with your example: https://github.com/strothj/react-docgen-typescript-loader/tree/bug/component-with-enum/packages/react-docgen-typescript-loader-example/src/components/ComponentUsingEnum
Can you check that I was understanding correctly?
@strothj Thanks for looking at this! Sorry for not responding for a week, I let time get away from me. I will try to make a reproduction repo to demonstrate what I'm seeing.
Hi, I've been experiencing a somewhat similar problem and thought it might help to let you know. I am still somewhat new to typescript so hopefully this makes sense :)
When I use Pick to declare my Props for a component all of the types are "any". If I declare them explicitly the types go through correctly.
For example:
interface A {
someString: string;
}
type B = Pick<A, 'someString'>;
If my component uses A as props, someString will be correctly defined as string in storybook. B will show up as any.
@justinanastos I'm closing this issue for house keeping purposes. Feel free to open a new issue.
@realalexhomer Your issue appears to have been fixed upstream. It works fine now from what I can tell.
Hello! I'm actually having the exact same issue as @justinanastos. The example in his original post is exactly what I'm seeing. If the type is an imported enum, then it displays as any instead of the enum in the props table.
@strothj any update on a fix for this?