Add shouldExtractValueFromUnion and fix default value bug #21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR includes two commits:
react-docgen-typescript
dependency to the latest versionshouldExtractValueFromUnion
parser option Note 1Screenshots
Before:
Now:
Note 1:
shouldExtractValueFromUnion
allows a more complete parsing thanshouldExtractLiteralValuesFromEnum
. It supports union types with multiple types (not only strings). I believe the latter is no longer needed, since the first covers the same scenarios, but I prefer to avoid a breaking change and keep supporting both, sincereact-docgen-typescript
also supports both.Note 2:
When using a default value that is not a string, the babel parser simply could not compile, as it was always expecting a string as default value. This is now fixed by transforming the
value
into a string. (See Problem with tests)Problem with tests:
Running the tests locally was not a problem (using node 12). However, the pre-commit also runs the tests and it constantly failed because of a known bug with node and the
toString
method (implicitly called in the template string transformation). I was not able to enforce this to run on node 11.12.0 or above (the version that fixes this issue). Are you able to add this? Or is this not an issue, since the tests run locally with no problem?Changelog and README:
I updated them as I thought it should be but you're free to update them as it best suits you.
Thanks.