Please include TypeScript types in the package itself
See original GitHub issueBefore you start - checklist
- I understand that React-PDF does not aim to be a fully-fledged PDF viewer and is only a tool to make one
- I have checked if this feature request is not already reported
Description
Currently TypeScript types are provided by an external @types/react-pdf
package. This allows the types definition to get out of sync with the react-pdf library.
Normally this wouldn’t be an issue, except currently a mistake in the types package actually breaks react-pdf itself.
react-pdf
uses"pdfjs-dist": "2.9.359",
@types/react-pdf
uses"pdfjs-dist": "^2.10.377"
As a result it’s possible that node_modules/pdfjs-dist
may be v2.10.377 while react-pdf uses v2.9.359. Because all of the PDF worker setup methods documented by react-pdf use node_modules/pdfjs-dist
, this means it’s possible that simply installing @types/react-pdf
can result in the pdfjs worker installed and the pdfjs library react-pdf uses being of different versions.
Proposed solution
Including the TypeScript types as part of the react-pdf package itself will permanently fix this issue by avoiding the duplication of the very specific dependency version.
- A) The .d.ts files from the
@types/react-pdf
package can be moved to react-pdf’s codebase and maintained alongside it - B) Using those .d.ts files, react-pdf could be refactored to TypeScript .tsx files so react-pdf is written in TypeSript.
Alternatives
Yes, it is possible to fix the @types/react-pdf
package for the current version (though the publishing method means this will likely take several days or even a week.
However even if we fix it now. Because react-pdf
pins an exact version of pdfjs the next time react-pdf updates its version of pdfjs (which is already outdated) this bug will regress and will need to be fixed again. Though this will likely not happen in a timely manor as someone will have to discover and re-investigate this bug (which only shows up at runtime) before submitting a PR to update the pdfjs version in the types package to match.
One other possibility would be to use peerDeps instead of deps for the pdfjs package. This would ensure that pdfjs is installed at the root, with the correct version, and it matches the version that react-pdf expects.
Additional information
No response
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:10 (5 by maintainers)
Top GitHub Comments
For anyone else who is having issues due to being unable to import the
PDFDocumentProxy
type, you can just use a workaround like:Note: v5.6.0 is now released, with pdfjs-dist bumped to 2.10.377.