-
Notifications
You must be signed in to change notification settings - Fork 4.6k
components: Expose TS types of props for public components #72831
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
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: 0 B Total Size: 2.38 MB ℹ️ View Unchanged
|
aduth
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is documented as an intentional decision to not export these types, and instead encourage React.ComponentProps for accessing the types.
gutenberg/packages/components/README.md
Lines 60 to 62 in 3be8bb2
| ### TypeScript | |
| This package exposes its own types for the components it exports, however it doesn't export its own types for component props. If you need to extract the props type, please use `React.ComponentProps` to get the types from the element. |
|
Proposing an alternative fix in #72979 |
|
Closing in favour of the proposed alternative - #72979 |
What?
As a part of #72032, we have added the
exportsfield to many packages includingcomponents. This prevents what was previously possible, i.e. to import component types from/build-typessub-path. But, once you defineexportsfor a package, you can't import from the sub-paths that are not defined inexportsfield, thus making it impossible to import type, should you need them.So, to ensure that any consumer component is able to import and use the types for component props, we are exposing them from the root.
Why?
To allow importing of TS types for component props.
How?
export * from '...')types.tsfilesBadge,DateCalendar, etc,Testing Instructions
Just verify that only the public components are exposed.
Testing Instructions for Keyboard
Screenshots or screencast