Add types
Hi,
Paged.js is insanely good! I spent hours on other PDF rendering engines and didn't even succeed to generate a table of content.
The only issue I have with pagedjs is there are no types provided with the package and no documentation of the classes and methods available.
Everytime I have a doubt about how to use something in PagedJS (which is often), I have to go to the Github repo, figure out the file, and then figure out the types.
Have you already considered adding types or even writing Pagedjs using TypeScript? And if you declined the idea, what is the reasoning behind?
Hi there! Thanks for the kind words!
When @fchasen started working on it, typescript wasn’t the thing it has become. So we got used to that, and since it’s vanilla, i dont think we got to think about it till now.
Fred, what do you say?
I usually just run npx -p typescript tsc src/**/*.js --declaration --allowJs --emitDeclarationOnly --outDir src to have the basic types after each release
I think that could be a good starting point to have types.
Just to clarify, this works when I use yarn berry to yarn patch pagedjs and put the changes back into the module.
exact steps @sampi is saying are:
yarn set version stable
yarn
yarn add pagedjs
yarn patch pagedjs
read the output:
- a directory
- a command when done
cd <1. the directory>
npx -p typescript tsc src/**/*.js --declaration --allowJs --emitDeclarationOnly --outDir src
<reopen original repo directory>
<2. the command>
yarn
from the last yarn run you should see something like :
> yarn
➤ YN0000: · Yarn 4.0.2
➤ YN0000: ┌ Resolution step
➤ YN0085: │ + pagedjs@patch:pagedjs@npm%3A0.4.3#~/.yarn/patches/pagedjs-npm-0.4.3-bada9a493b.patch::version=0.4.3&hash=2a48a1
➤ YN0000: └ Completed in 0s 421ms