Skip to content
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

Try react-docgen-typescript #12

Closed
typicode opened this issue Jun 10, 2018 · 7 comments
Closed

Try react-docgen-typescript #12

typicode opened this issue Jun 10, 2018 · 7 comments

Comments

@typicode
Copy link
Owner

Currently only Flow and PropTypes are supported, but https://github.com/styleguidist/react-docgen-typescript (or other libs) may improve TypeScript support

@alexdriaguine
Copy link

I wanted to have a go at this and experimented a bit with react-docgen-typescript, but it seems it's a bit limited for composed interfaces as props.

Say I have props that look something like this

interface Address  {
  street: string,
  street2?: string,
  pincode: number
}

interface Commit {
  id: string,
  message: string
}

interface Repo  {
  url: string,
  demoSite?: string,
  npm?: string,
  commits: Array<Commit>
}

interface Person  {
  id: number,
  name: string,
  age: number,
  address: Address,
  family?: Array<number>,
  repos: Array<Repo>
}

interface Props  {
  person: Person
}

The information i get back from parsing the component is

{
  person: {
    defaultValue: null,
    description: '',
    name: 'person',
    parent: {
      fileName: 'react-fake-props/fixtures/typescript/Component.tsx',
      name: 'Props',
    },
    required: true,
    type: {name: 'Person'},
  },
}

No reference to the Person interfaces fields, just the name. So might want to look at other options or using typescript itself to grab the information. 🙂

@typicode
Copy link
Owner Author

Hi @alexdriaguine,

Thanks a lot for giving it a try and sharing 👍. Tried too and got the same results.
I guess for the moment TypeScript support will be postponed until there are progress in "docgen" tools.

@typicode
Copy link
Owner Author

Closing this issue as react-docgen seems to be able to extract information from TypeScript now as well.

@typicode
Copy link
Owner Author

See #18

@timini
Copy link

timini commented May 30, 2019

Might also be worth looking at https://github.com/google/intermock

@typicode
Copy link
Owner Author

typicode commented Jun 5, 2019

Thanks @timini 👍 interesting, I din't know about this one.

@timini
Copy link

timini commented Jun 5, 2019

For typescript in the end I managed to generate a json schema from the interface using https://github.com/YousefED/typescript-json-schema then it is fairly simple to generate fake data from the json schema (ended up using json-schema-faker) if there was one package for this whole workflow it would make things a lot easier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants