question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Better support for custom types

See original GitHub issue

This is more of a “would you be willing to accept a pull request which does this?” question than an issue of sorts. 😃

I would really like to extend the functionality of “custom” types so that:

  1. We support destructured imports (Eg. PropTypes.array - note the lack of React.)
  2. We allow common react-esque prop type function patterns to be picked up with custom props in the same way that arrayOf is currently handled. (Eg. PropTypes.iterableOf(PropTypes.record(User)))

Basically I feel the library should be able to support custom user prop types in such a way we don’t have to reparse the raw value which would mean anyone can easily implement simple custom prop types and create documentation from that.

Custom prop types are super useful in building a real-world app with React and so I would like to see how we can help developers document these too.

We, at Lystable, want to build an open living component docs solution and are hoping react-docgen can feature at the core!

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:1
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
chrisuicommented, Sep 19, 2015

To clarify here are a few examples:

Ex 1. Firstly the destructuring pattern should be supported.

static propTypes = {
  prop: PropTypes.string
}

// yields {type: {name: 'string'}}

Ex 2. With the above the [x].isRequired would be a common pattern we can extract.

static propTypes = {
  prop: PropTypes.string.isRequired
}

// yields {type: {name: 'string'}, required: true}

Ex 3. Custom function prop-types should be supported.

static propTypes = {
  prop: PropTypes.record(User)
}

// yields {type: {name: 'record', value: 'User'}}

Ex 4. Again, .isRequired pattern should be honoured.

static propTypes = {
  prop: PropTypes.record(User).isRequired
}

// yields {type: {name: 'record', value: 'User'}, isRequired: true}

Ex 5. Function pattern will support nested types.

static propTypes = {
  prop: PropTypes.iterableOf(PropTypes.record(User))
}

// yields {type: {name: 'iterableOf', value: {name: 'record', value: 'User'}}}

Ex 6. To confirm, these custom props can be used deeply.

static propTypes = {
  prop: PropTypes.iterableOf(PropTypes.oneOf([PropTypes.record(User), PropTypes.bool])
}

// yields {type: {name: 'iterableOf', value: {name: 'enum', values: [{name: 'record', value: 'User'}, ...]}}}

Notes/thoughts:

  • Custom enum syntax is not needed as standard oneOf covers any possible usage of this.
  • .raw should still be present on the type object
  • This output implements a breaking change now that name: 'custom' has gone.
    • Can’t see this as being an issue as .raw still exists and consumers can still do the same stuff
    • If this is an issue we could just have a new .customName property.
0reactions
levithomasoncommented, Aug 25, 2016

Ditto. I’m also wondering if this may actually become a plugin in light of #115.

Read more comments on GitHub >

github_iconTop Results From Across the Web

add better support for custom types · Issue #1829 - GitHub
right now, to add a new type to pydantic, we have to create a custom class and add validation logic to it. this...
Read more >
How To Create Custom Types in TypeScript - DigitalOcean
Though the pre-made, basic types in TypeScript will cover many use cases, creating your own custom types based on these basic types will ......
Read more >
Rails 7 adds better support for custom enum types in ...
PostgreSQL provides in-built support for enumerated types that Rails can then take advantage of. However, it is often a pain to make use...
Read more >
How to support multiple custom types? - Stack Overflow
When i find a type I convert the string to the appropriate type. However how can i improve this so that is it...
Read more >
Custom Types - Open Source by greenrobot
Learn how to add support for a custom types using greenDAO. Custom types allow entities to have properties of any type.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found