strothj / react-docgen-typescript-loader

Webpack loader to generate docgen information from Typescript React components.
Other
360 stars 47 forks source link

Type defined in another file #52

Closed affanshahid closed 4 years ago

affanshahid commented 4 years ago

So I am importing a type from another file and using that as a type in one of my prop declarations:

import Task, { TaskInfo } from './Task';

export interface TaskListProps {
  loading?: boolean;
  tasks?: TaskInfo[]
};

I get the following: image

Notice the any[]. Am I doing something wrong?

henck commented 4 years ago

I can verify that any type declared in a different file shows up as any.

sami616 commented 4 years ago

I can verify this is also happening to me

sergiop commented 4 years ago

@affanshahid I don't know if it's related, but with this:


type Type = 'default' | 'action' | 'destroy'

export interface ButtonProps {
  label?: string
  type?: Type
}

I get the following:

Schermata 2019-10-03 alle 23 32 06

Instead of this:

Schermata 2019-10-03 alle 23 32 41
kelly-tock commented 4 years ago

this is different @affanshahid I think but I would like this as well! I have union types defined that I use in multiple places,

export type TextColors = 'DEFAULT' | 'DISABLED';

and I just see TextColors as the description.

gilbarbara commented 4 years ago

I'm having a similar problem with union types but if I set the property as optional it expands the type...

Screen Shot 2019-11-05 at 21 32 24
gilbarbara commented 4 years ago

Setting shouldExtractLiteralValuesFromEnum to true in the loader options fixed for me. 🎉

strothj commented 4 years ago

For support for enums, some info can be found here: https://github.com/strothj/react-docgen-typescript-loader/issues/87

For loading types from external files: https://github.com/strothj/react-docgen-typescript-loader/issues/80

The documentation was recently updated to include instructions on supporting files loaded from external files. I'm closing this issue but feel free to leave a comment if this is still a problem.