reactjs / reactjs/react-docgen

@defaultValue is not parsed from interface

Open
#901 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
3.8k
Forks
316
Avg merge
5h 7m
Merged PRs (30d)
4

Description

The following code tested in the playgroud https://react-docgen.dev/playground

interface Props {
  /** 
   * The name to greet
   *
   * @defaultValue 'something'
   */
  name: string;
}

/**
 * Hello world component
 */
const MyComponent = (props: Props) => {
  return <div />;
}

returns:

[
  {
    "description": "Hello world component",
    "displayName": "MyComponent",
    "methods": [],
    "props": {
      "name": {
        "required": true,
        "tsType": {
          "name": "string"
        },
        "description": "The name to greet\n\n@defaultValue 'something'"
      }
    }
  }
]

I think the defaultValue property is missing and should appear in the result, and part of the description "@defaultValue 'something'" should be removed.

[
  {
    "description": "Hello world component",
    "displayName": "MyComponent",
    "methods": [],
    "props": {
      "name": {
        "required": true,
        "tsType": {
          "name": "string"
        },
        "description": "The name to greet",
        "defaultValue": {
          "value": "'something'",
          "computed": false
        }
      }
    }
  }
]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the TypeScript interface example in the react-docgen playground and inspect how its JSDoc tags are parsed. Confirm that @defaultValue is removed from the description and emitted as a non-computed defaultValue with the expected value; use the shown output as the completion check.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.