React-pdf: Add pdfjs to @types/react-pdf

Created on 25 Jun 2019  ·  6Comments  ·  Source: wojtekmaj/react-pdf

Before 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

Is your feature request related to a problem? Please describe.

When importing pdfjs from the package (to define the remote worker) typescript can't compile because the definition doesn't exist on DefinitelyTyped

Describe the solution you'd like

Add the definition to the package

enhancement help wanted

Most helpful comment

This has been merged as is now available in @types/react-pdf@^4.0.3. Make sure to delete your yarn.lock file to get @types/pdfjs-dist@^2.1.1 type changes as well.

Thanks @CodeDaraW for review.

All 6 comments

Maybe @CodeDaraW who created the types could be of any help?

You can import pdfjs from pdfjs-dist directly, that's the same thing.
I didn't import the type definition of pdfjs-dist, you may create a Pull Request for it.

I added basic support for this by exporting version and GlobalWorkerOptions from @types/pdfjs-dist, and then exporting pdfjs-dist as pdfjs from @types/react-pdf.

import { Document, Page, pdfjs } from 'react-pdf';
pdfjs.GlobalWorkerOptions.workerSrc =
  `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`;

Example above now works in TypeScript.

@wojtekmaj @CodeDaraW

This has been merged as is now available in @types/react-pdf@^4.0.3. Make sure to delete your yarn.lock file to get @types/pdfjs-dist@^2.1.1 type changes as well.

Thanks @CodeDaraW for review.

Maybe @wojtekmaj can close the issue now.

Wow! Thanks so much to everyone involved.

Was this page helpful?
0 / 5 - 0 ratings