Skip to content

feat: extract props from TypeScript Pick and Omit - #1198

Open
n-hiraha wants to merge 1 commit into
reactjs:mainfrom
n-hiraha:ts-pick-omit-props
Open

n-hiraha wants to merge 1 commit into
reactjs:mainfrom
n-hiraha:ts-pick-omit-props

Conversation

@n-hiraha

Copy link
Copy Markdown

Fixes #925.

Props typed with Pick<T, K> or Omit<T, K> were dropped. For example, props: Pick<Base, 'a'> produced no props, Omit<Base, 'b'> & { c: boolean } produced only c, and interface Props extends Pick<Base, 'a'> reported Pick in composes.

This adds support when K is a string or number literal, or a union of them:

  • Pick keeps the listed members of T and Omit drops them. Descriptions and required come from the original members.
  • Works directly on the props parameter, in type aliases, in intersections, in interface extends, and nested (Omit<Pick<T, 'a' | 'b'>, 'b'>).
  • Type arguments of the source are bound, so Pick<Base<string>, 'value'> gives value: string.
  • A locally declared or imported type named Pick or Omit is left alone.
  • If T cannot be resolved (for example it is imported from another package), interface Props extends Pick<LinkProps, 'href'> now adds LinkProps to composes instead of Pick.
  • Keys that are not literals, such as Omit<T, keyof Other>, behave as before.

Implementation notes:

  • resolveGenericTypeAnnotation now returns a builtin Pick/Omit reference as is, so a type alias such as type Props = Omit<Base, 'c'> still reaches the new code.
  • The source type of a Pick/Omit is read with its own visited set, so Pick<T, 'a'> & Omit<T, 'a'> reads T twice. To keep cycles safe, applyToTypeProperties also tracks the types on the current path (a new optional ancestors argument). Everything else keeps the existing visited set, so output for other types is unchanged.

Tests: added 12 cases to codeTypeHandler-test.ts. Without the change, 10 of them fail. The other 2 (a Pick of the interface that extends it, and a local type Pick) guard against regressions. The full react-docgen suite passes (1526 tests), along with tsc, ESLint and Prettier.

@netlify

netlify Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for react-docgen ready!

Name Link
🔨 Latest commit d8fdfd0
🔍 Latest deploy log https://app.netlify.com/projects/react-docgen/deploys/6af2a0e8c2aa765f5889252e
😎 Deploy Preview https://deploy-preview-1198--react-docgen.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@changeset-bot

changeset-bot Bot commented Nov 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d8fdfd0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
react-docgen Minor
@react-docgen/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant