reactjs / reactjs/react-docgen

Using `Readonly<T>` utility type results in losing pieces of `T`'s information

Open
#905 0 comments 6 reactions 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

You can paste the code below in the playground and see that description and tsType are lost.

interface Props {
  /** The name to greet */
  name: string
}

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

/**
 * Hello world Readonly
 */
const MyReadonlyPropsComponent = ({name = 'world'}: Readonly<Props>)=> {
  return <div />;
}

I noticed this behaviour while digging through an issue that appeared after the latest Storybook's major update, which uses this package by default to extract information from the components.

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 issue in the linked playground using the two component examples and compare the extracted results for Props and Readonly. The fix is complete when the Readonly result retains the prop description and tsType information shown for Props.

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
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.