Skip to content
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.

Access property type for documentation purposes at run time #60

Open
zerekw opened this issue May 18, 2017 · 4 comments
Open

Access property type for documentation purposes at run time #60

zerekw opened this issue May 18, 2017 · 4 comments

Comments

@zerekw
Copy link

zerekw commented May 18, 2017

Looking at how storybook and random questions on the internet it looks like it would be preferable to be able to pull the type of the property after it has been set.

I have a simple POC I can submit as a PR if that would be preferred. Code below as to what I would be expecting to have as an end result.

// this would be set with the validator
function getType() {
      return {
        type: type,
        subType: subType
      }
    }
propEnum.getType() => {type: "enum", subType: Array(4)}
propString.getType() => {type: "string", subType: undefined}
@zerekw zerekw changed the title Access property type for documentation purposes Access property type for documentation purposes at runTime May 18, 2017
@zerekw zerekw changed the title Access property type for documentation purposes at runTime Access property type for documentation purposes at run time May 18, 2017
@oomathias
Copy link

It looks like an interesting idea, I'm playing with react-docgen which doesn't work well in every case. I've seen packages like react-desc that tries to do that by surcharging prop-types.

Being able to retrieve the propTypes in a JSON format would be so much easier. The only thing missing would be the description/comment.

What I actually need:

  • prop name
  • type
  • isRequired
  • description

@dennisreimann
Copy link

Has the idea of adding something like a description function to prop-types been discussed before? I couldn't find something via the search and came here looking for a similar solution as I am also working on a documentation tool.

Person.propTypes = {
  name: PropTypes.string.isRequired.description("The persons first and last name")
}

Another idea we had was adding a proprietary attribute like propDescriptions, similar to defaultProps:

Person.propDescriptions = {
  name: "The persons first and last name"
}

See also diegohaz/parse-prop-types#6

@ljharb
Copy link
Contributor

ljharb commented Dec 20, 2018

Isn't the name of the prop the description already?

@dennisreimann
Copy link

Oftentimes yes, but in some cases its useful to describe the prop a bit further.

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

No branches or pull requests

4 participants