react-share: Type errors after migrating to v4
I migrate to v4 and I’m now getting these type errors:
Type '{ children: Element; url: string; }' is missing the following properties from type 'Pick<Props<{ quote?: string; hashtag?: string; }>, "form" | "style" | "title" | "type" | "name" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | ... 264 more ... | "resetButtonStyle">': form, title, type, name, and 256 more.
I’m using it like this, nothing special:
<FacebookShareButton url={url}>
<FacebookIcon {...iconProps} />
</FacebookShareButton>
It seems to require all props including native ones. I checked out the demo and it works as expected. I’m on the latest react and typescript versions.
Any ideas? @nygardk
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 14
- Comments: 16 (1 by maintainers)
@nygardk any updates please ?
Found a workaround until: https://medium.com/@tomsoir/typescript-how-to-rewrite-type-definition-file-file-d-ts-of-any-node-modules-package-1eed7f5630d1
For me, this one was solved by install/update of
@types/react
package. I had it at 16.9.5 and 16.9.35 silenced the warnings. Might possibly also fix #301I believe the issue is here: https://github.com/nygardk/react-share/blob/e72dba51654c8277b9cfd87b9e8f354b36017fd3/src/hocs/createIcon.tsx#L3
The Props required by Icon inherit all SVGProps (except width and height). I think this would be a simple fix of changing
Omit<React.SVGProps<SVGSVGElement>, 'width' | 'height'>
toOmit<Partial<React.SVGProps<SVGSVGElement>>, 'width' | 'height'>
My workaround is currently the following:
Far from ideal, though it’s basically the same as redeclaring an export as
any
.I upgraded react types and it seemed to do the trick.
"@types/react": "16.9.35"