dcdunkan / telegraph

Telegra.ph API wrapper for JavaScript
https://jsr.io/@dcdunkan/telegraph
MIT License
22 stars 4 forks source link

Library not working #5

Closed code-withAshish closed 2 years ago

code-withAshish commented 2 years ago

@dcdunkan

Problem

The library is not working for me as i tried to just simply create a new telegraph account through the api , code for which is provided below and following that the error that was thrown on my system.

Code

import { Telegraph } from "https://deno.land/x/telegraph/mod.ts";

//create new telegraph account
const tp = new Telegraph({
    short_name: "Ashish",
    author_name: "Ashish Bhushan Kumar",
})

await tp.setupAccount();

console.log(tp.token);

Error

error: TS2339 [ERROR]: Property 'href' does not exist on type 'NamedNodeMap'.
  if ("href" in el.attributes) nodeElement.attrs = { href: el.attributes.href };
                                                                         ~~~~
    at https://deno.land/x/telegraph@v1.0.2/src/parse.ts:121:74

TS2339 [ERROR]: Property 'src' does not exist on type 'NamedNodeMap'.
    let src = el.attributes.src;
                            ~~~
    at https://deno.land/x/telegraph@v1.0.2/src/parse.ts:123:29

Found 2 errors.

Steps taken

I tried to look into the library and locating where this type error is coming from and i traced it back to this part here in https://github.com/dcdunkan/telegraph/blob/e6771ac6a9262933136914c9b2908f487ac48531/src/parse.ts#L121

the typescript compiler shows that

 TS2339 [ERROR]: Property 'href' does not exist on type 'NamedNodeMap'.

and i could not find any other solution.

Possible error

I think that the deno modules imported in deps.ts are implicitly using the latest version and that might not play well with the existing code which might have been written on a previous version, so i suspect something broke on the new update in any of the dependencies.

https://github.com/dcdunkan/telegraph/blob/e6771ac6a9262933136914c9b2908f487ac48531/deps.ts#L1-L4

That's just my opinion though!!!

dcdunkan commented 2 years ago

This was fixed in 60940ad. As you suspected, it was an issue with dependency version. Thank you for reporting! :)

Try importing the library from v1.0.3