Skip to content

Conversation

argshook
Copy link
Contributor

hello!

i noticed that react-docgen-typescript is not able to parse referenced default props. This means the following is okay:

static defaultProps = { /* ... */ }

but the following breaks:

const defaultProps = { /* ... */ };
// later in class
static defaultProps = defaultProps

here's mocha complaining

  parser
    component with default props
      ✓ should parse defined props (563ms)
      1) should parse referenced props


  1 passing (952ms)
  1 failing

  1) parser
       component with default props
         should parse referenced props:
     TypeError: Cannot read property 'reduce' of undefined
      at getPropMap (src/parser.ts:466:29)
      at Parser.extractDefaultPropsFromComponent (src/parser.ts:422:23)
      at Parser.getComponentInfo (src/parser.ts:208:33)
      at src/parser.ts:132:28
      at Array.map (native)
      at Object.parse (src/parser.ts:132:10)
      at Object.parse (src/parser.ts:67:58)
      at Object.check (src/__tests__/testUtils.ts:37:18)
      at Context.<anonymous> (src/__tests__/parser.ts:219:7)

this PR makes react-docgen-typescript support referenced default props.

However, due to my very limited knowledge of typescript parser, the implementation feels wonky to me. Moreover, this PR does not consider default props being imported from another file. This should be done in separate PR anyway.

Please let me know what you think. It'd be great to get this feature working as currently im unable to generate documentation for a bunch of components.

Thanks for your work!

prove that `defaultProps`, when referenced, break parser
@argshook
Copy link
Contributor Author

@pvasek ping

@pvasek pvasek merged commit ad1f723 into styleguidist:master Apr 25, 2018
@pvasek
Copy link
Collaborator

pvasek commented Apr 25, 2018

I somehow missed that. Sorry for that.

@argshook argshook deleted the fix/default-props branch April 25, 2018 14:53
@pvasek
Copy link
Collaborator

pvasek commented Apr 25, 2018

The version v1.3.1 including this fixed has just been released.

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

Successfully merging this pull request may close these issues.

2 participants