react-docgen-typescript-loader icon indicating copy to clipboard operation
react-docgen-typescript-loader copied to clipboard

Imported `enum` types are displayed with propType "any"

Open justinanastos opened this issue 7 years ago • 9 comments
trafficstars

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;

justinanastos avatar Jun 09 '18 16:06 justinanastos

Thank you for the issue report! I will investigate this tomorrow (Sunday).

strothj avatar Jun 09 '18 17:06 strothj

Thanks @strothj !

justinanastos avatar Jun 09 '18 18:06 justinanastos

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.

strothj avatar Jun 10 '18 16:06 strothj

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 avatar Jun 10 '18 17:06 strothj

@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.

justinanastos avatar Jun 16 '18 13:06 justinanastos

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.

realalexhomer avatar Jun 28 '18 16:06 realalexhomer

@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.

strothj avatar Feb 15 '19 20:02 strothj

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.

sierracrum-riskalyze avatar Dec 04 '19 00:12 sierracrum-riskalyze

@strothj any update on a fix for this?

sierracrum-riskalyze avatar Aug 27 '20 19:08 sierracrum-riskalyze