-
-
Notifications
You must be signed in to change notification settings - Fork 84
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
It is not supporting the TS type declaration. #135
Comments
Hi, thanks for the heads up! There are currently no TypeScript types defined for pdfreader. But that would be a nice addition indeed! I'm guessing that writing a @Basavarajrp, would you be interested in doing it and proposing this evolution as a Pull Request? I can help if needed. |
Hi @adrienjoly , I'm excited to contribute to this repository by adding the type declaration files. I appreciate your help and guidance on where to start and how to get things going. 😊 Thank you! |
Awesome! Here's the official procedure on how to add type declarations in a npm package: https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html#including-declarations-in-your-npm-package Here is the steps to follow in order to contribute that change to
Let me know if your need assistance on any of these steps. |
Hi @adrienjoly , Thank you for this guidance, I will work on it and get back to you if any help is needed. Tq 😊. |
This paragraph may be helpful:
Cf TypeScript: Documentation - ECMAScript Modules in Node.js |
I wrote a very weak mockup since I am interested in using just those 2 functions (parseFileItems, parseBuffer), maybe you guys can pick up from it and make it full: declare module "pdfreader" {
type InitOptions = { password?: string; debug?: boolean };
type Error = null | string;
type DataEntry = {
page?: number;
width?: number;
height?: number;
text?: string;
file?: {
path?: string;
buffer?: string;
};
} | null;
type ItemHandler = (err: Error, data: DataEntry) => void;
class PdfReader {
constructor(opts: InitOptions | null): PdfReader;
parseFileItems(pdfFilePath: string, itemHandler: ItemHandler): void;
parseBuffer(buffer: Buffer, itemHandler: ItemHandler): void;
}
} Right now I am facing this issue: modesty/pdf2json#303 |
Hi @niemal and @adrienjoly I started working on this, I'm wondering whether I should create a separate project and publish it as an npm package. Alternatively, should I include declarations within the same repository? I've noticed various projects that maintain distinct repositories solely for type declarations. Please provide your guidance and insights. Also, I heard about According to the previous conversation with @adrienjoly I think I need to follow this following stpes. Here's what you can do:
|
I edited the above mockup to the following, seems to be more ideal to the way things are exported. I am trying to make it work with Next.js so I will get back to you with the working version when that happens. For the moment I cloned both of this repo and pdf2json one, importing them internally and see what works and what not. This is export type InitOptions = { password?: string; debug?: boolean };
export type Error = null | string;
export type DataEntry = {
page?: number;
width?: number;
height?: number;
text?: string;
file?: {
path?: string;
buffer?: string;
};
} | null;
export type ItemHandler = (err: Error, data: DataEntry) => void;
export declare class PdfReader {
constructor(opts: InitOptions | null): PdfReader;
parseFileItems(pdfFilePath: string, itemHandler: ItemHandler): void;
parseBuffer(buffer: Buffer, itemHandler: ItemHandler): void;
} |
@niemal , are you working on this? Or should I continue working on this? I am happy to work on this. |
You should continue to work on this, I am working on something else but I am happy to provide any input I can. |
This worked successfully after using a static folder with a stand-alone pdf2json as a module in Next.js and importing that stand-alone pdf2json to use. You will probably want to use the above file as a basis to further write-up all the classes that are exported (except PdfReader). |
Good job!
Would you be interested to contribute that file into pdfreader’s official
repository, by sending a pull request?
Let me know if you want assistance in doing that.
Adrien
|
|
Version 3.0.1 includes the type definitions your proposed in your pull request. Thank you for your contribution! |
Hello Team (@adrienjoly and @niemal), I have created the type declaration files for all the modules and here you can check them. master...Basavarajrp:npm-pdfreader:master "Please let me know if I'm heading in the right direction. While I still need to test and refine this further, I would appreciate your input on whether my current progress is on track." |
This looks pretty solid on first sight! Have you tested it on a typescript project? Regarding Next.js, the problem is with pdf2json not being imported as a stand-alone module so what worked for me was having it in a directory exported as a module and have pdfreader using that (I didn't npm install either of those). I will see if I can squeeze some time to test this but if you have tested it using it in a typescript project then you should certainly make a pull request and delete my own code (index.d.ts). |
Now I have not tested completely, but when I tried I was not getting any type specific errors while using Boolean values instead string just to test. So I need help on this testing I will continue more on this on my next work cycle. |
I've created the This is my tsconfig.json file: Any corrections needed here.
This is the problem I am stuck with now. cc: @adrienjoly and @niemal |
Hello @niemal, I wanted to let you know that I've implemented a workaround for the issue we discussed. I created an @niemal, could you kindly take a look at this pull request? I'd appreciate it if you could confirm whether the issue you raised has also been resolved now with this implmentation. Branch : 🙃 Thank you for your time and assistance. |
Hey, First off the issue I mentioned is not an issue of this package but pdf2json and no it didn't resolve, unfortunately. I think we should implement a proper full Cheers! |
Hi! Can you summarize and clarify what objective we're targeting here? What do you want to be able to do with these type definitions, exactly? |
We have decided to include type definitions for the entire project. Since I opened this issue to address the lack of TypeScript support in the package, I have taken the initiative to add the TypeScript type definition files to provide the necessary support. |
Ok. So far, I've already merged 2 PRs related to typing, in less than a week. => I'd appreciate it if you could converge to a final PR that you both tested and agree on. I'll be happy to review and merge it when you're fully done with it. To clarify, my hope is to not have to review yet another PR about typing after merging that one. If you have specific questions, I'll do my best to answer them. Thank you for your understanding. Adrien |
Just in case it was not clear in my last message: feel free to keep discussing and collaborating together here if it's convenient for you. Let me know when your PR is ready for review. Thank you! ^^ Adrien |
Hello everyone, I made a pull request for type definitions for the TableParser class. Please feel free to point out improvements I could make to this. |
Describe the bug
Could not find a declaration file for module 'pdf reader'
To Reproduce
import { PdfReader } from "pdfreader";
Tq 🙃.
The text was updated successfully, but these errors were encountered: