seek-oss / playroom

Design with JSX, powered by your own component library.
MIT License
4.45k stars 183 forks source link

TypeScript configurations not fully parsed #241

Closed AndrewLeedham closed 2 years ago

AndrewLeedham commented 2 years ago

The addition of reactDocgenTypescriptConfig is great! So I started playing around with it, but couldn't get a bunch of my components to work when they referenced types from other .tsx files. After a bunch of digging and red herrings, I found that playroom is not parsing tsconfig.json it is just reading the file as is, meaning things like extends does not work.

The code in question is here: https://github.com/seek-oss/playroom/blob/master/lib/getStaticTypes.js#L31-L34. This just reads in the config, so when using extends the other configs being extended are not resolved.

There are 2 solutions to this problem I can come up with:

  1. Use ts.parseJsonConfigFileContent to properly parse the config. This is what react-docgen-typescript does itself: https://github.com/styleguidist/react-docgen-typescript/blob/master/src/parser.ts#L159
  2. Use withCustomConfig and just pass the file path straight to react-docgen-typescript. The issue with this approach however is that noErrorTruncation would not be able to be set.