Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

required field is always false #321

Closed
davidfirst opened this issue Jan 28, 2019 · 4 comments
Closed

required field is always false #321

davidfirst opened this issue Jan 28, 2019 · 4 comments

Comments

@davidfirst
Copy link

I get "required": false also when I set my variable to be required, e.g. PropTypes.number.isRequired.

An example code

MyComponent.propTypes = {
  foo: PropTypes.number.isRequired,
};

I get

{
  "description": "General component description.",
  "displayName": "MyComponent",
  "methods": [],
  "props": {
    "foo": {
      "type": {
        "name": "number"
      },
      "required": false,
      "description": "",
      "defaultValue": {
        "value": "42",
        "computed": false
      }
    }
  }
}
@danez
Copy link
Collaborator

danez commented Jan 28, 2019

Which version of react-docgen are you using?

@davidfirst
Copy link
Author

davidfirst commented Jan 29, 2019

The latest. 3.0.0.
The code I used is from the readme. (which by the way threw an error, until I replaced render: function() { with render: () => { ).

@danez
Copy link
Collaborator

danez commented Jan 31, 2019

Thanks for reporting I was able to reproduce this.

@danez danez added bug and removed bug labels Jan 31, 2019
@danez
Copy link
Collaborator

danez commented Feb 1, 2019

After inspecting, there is not really a problem. The confusion with the example comes because foo in that example has a default value. Props with a default value are never required even if isRequired is set. The problem is more, that the definition of the component is wrong. One should not use isRequired and then define a defaultValue.

I will fix the example.

@danez danez closed this as completed Feb 1, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 28, 2022
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

2 participants