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

Fix icons type annotation #26129

Merged
merged 1 commit into from Oct 15, 2020
Merged

Fix icons type annotation #26129

merged 1 commit into from Oct 15, 2020

Conversation

sarayourfriend
Copy link
Contributor

@sarayourfriend sarayourfriend commented Oct 14, 2020

Description

From @sirreal:

'SVG' isn’t something we can get the props for in ComponentPropsWithoutRef<'SVG'> — It would have to be the SVG component type or just the SVGProps like in the diff

svg would work better (or should) but doesn't actually, for whatever reason. The following does work though (you can see that className for example will now show in the intellisense for Icon's props.

How has this been tested?

Tested using intellisense

Screenshots

VS Code's Intellisense showing all the expected attributes available now that the type is corrected

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@sirreal sirreal added [Type] Code Quality Issues or PRs that relate to code quality [Package] Icons /packages/icons labels Oct 15, 2020
@sirreal
Copy link
Member

sirreal commented Oct 15, 2020

svg would work better (or should) but doesn't actually, for whatever reason. The following does work though (you can see that className for example will now show in the intellisense for Icon's props.

"svg" (quoted) works well:

/** @typedef {{icon: JSX.Element, size?: number} & import('react').ComponentPropsWithoutRef<'svg'>} IconProps */

However, it's the props for the raw HTML svg component. That's missing the isPressed?: boolean prop that's added to the SVG component wrapper. We can either get the props from the SVG component type:

/** @typedef {{icon: JSX.Element, size?: number} & import('react').ComponentPropsWithoutRef<import('@wordpress/primitives')['SVG']>} IconProps */

But they're already accessible directly from the primitives package like is done in this change:

/** @typedef {{icon: JSX.Element, size?: number} & import('@wordpress/primitives').SVGProps} IconProps */

Copy link
Member

@sirreal sirreal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix 👍

@sirreal sirreal merged commit 4973020 into WordPress:master Oct 15, 2020
@github-actions github-actions bot added this to the Gutenberg 9.2 milestone Oct 15, 2020
@sarayourfriend sarayourfriend deleted the fix/icon-types branch October 15, 2020 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Icons /packages/icons [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants