ibrod83 / nodejs-web-scraper

81 stars 26 forks source link

[Feature] Add types #33

Open lnfel opened 1 year ago

lnfel commented 1 year ago

I hope this satisfies #32, only added types from what I can understand of the code at the moment. Will push updates as soon as I learn more about the structure of the data being used internally.

ibrod83 commented 1 year ago

Thank you for the PR. I'll take a look at it later on

ibrod83 commented 1 year ago

So I tested the code a bit, and it seems to me that are many types missing. For example, "CollectContent" class doesn't have any type associated with it. Also, there are "incomplete types", like RootConfig: export type RootConfig = { // Look at the pagination API for more details. pagination?: any; getPageData?: Function; getHtml?:Function // Receives a dictionary of children, and an address argument getPageObject?: Function; // Receives an axiosResponse object getPageResponse?: Function; // Receives htmlString and pageAddress getPageHtml?: Function; // Listens to every exception. Receives the Error object. getException?: (error: Error) => Promise<any>; } & HttpOperationConfig; The "Function" type doesn't specify parameters and return value. This raises an error in my typescript client code. Also, RootConfig seems to be missing "getHtml" hook. What version and configuration of Typescript are you using? Perhaps it's less strict?

lnfel commented 1 year ago

Yes, there are tons of missing types. I am using VSCode's bundled TS which is 5.2.2, maybe we could setup a tsconfig.json to explicitly include strict type checking. Gonna make some time for it this weekend.