-
-
Notifications
You must be signed in to change notification settings - Fork 907
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
Please include TypeScript types in the package itself #899
Comments
I'm all for refactoring React-PDF to TypeScript actually, but frankly, I don't even know how to start. Regardless, I suggest raising an issue in DefinitelyTyped repo to resolve the issue for now. |
Actually I just went to write a PR to fix the issue. However it appears this is not fixable on the DefinitelyTyped side. It appears that the TypeScript types for [email protected] are missing a type ( So fixing the types package may actually require react-pdf to upgrade its version of pdfjs-dist first. |
Maybe it's possible to do this incrementally.
|
My client is open to giving me 2 days to spend on refactoring react-pdf to TypeScript, with a bit of interruption for higher priority stuff. Not sure I can finish a full refactor in that time but it should give you a start. You could start by upgrading pdfjs-dist to |
2.10.377 is definitely on my radar! Missed that release being marked as stable. Thanks for the heads up. Tracked under #900. |
I also ran into the same issue about the unalignment of pdfjs-dist version when doing a full reinstall of my project's deps after upgrade to npm 8 without the package-lock. |
Note: v5.6.0 is now released, with pdfjs-dist bumped to 2.10.377. |
For anyone else who is having issues due to being unable to import the import { Document, DocumentProps } from 'react-pdf'
type LoadCallback = Required<DocumentProps>['onLoadSuccess']
function Display() {
const onLoad: LoadCallback = useCallback((pdf) => {
console.log(pdf.numPages) // `pdf` is properly typed here
...
}, [])
return (
<Document loading="" file={url} onLoadSuccess={onLoad}>
...
</Document>
)
} |
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this issue will be closed in 14 days. |
For those of you who actually need to access type LoadCallback = Required<DocumentProps>['onLoadSuccess']
type PDFDocumentProxy = Parameters<LoadCallback>[0] |
Before you start - checklist
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 usenode_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.
@types/react-pdf
package can be moved to react-pdf's codebase and maintained alongside itAlternatives
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
The text was updated successfully, but these errors were encountered: