cheerio@1.0.0-rc12 has itself type files, drop @type/cheerio dependency please
Closed this issue ยท 12 comments
ref: https://unpkg.com/browse/cheerio@1.0.0-rc.12/lib/cheerio.d.ts
I can make a PR if possible.
They don't seem to be usable.
I don't see types for cheerio elements, such as Element
and TagElement
defined in @types/cheerio
.
Then function itself, which has type Cheerio
in types, is a mixin in that file, I'm not sure what <T>
is supposed to be there.
I used cheerio@1.0.0-rc12
in my project. After I install @iconify/tools
, my written script encounter ts error, because my scripts depends on cheerio@1.0.0-rc12
types, but ts load types from @types/cheerio
.
I don't see types for cheerio elements, such as Element and TagElement defined in @types/cheerio.
Then function itself, which has type Cheerio in types, is a mixin in that file, I'm not sure what is supposed to be there.
I will try to test it recently.
What error message are you getting?
Failed to compile.
../path/to/heading-elements.ts:20:34
Type error: Property 'tagName' does not exist on type 'Element'.
Property 'tagName' does not exist on type 'TextElement'.
18 | const text = $(item).text()?.trim()
19 | if (typeof text === 'string' && !text) {
> 20 | messages.push(`<${item.tagName.toLowerCase()}> textContent is empty`)
| ^
21 | }
22 |
23 | if (index === 0 && item.tagName.toLowerCase() !== 'h1') {
With this error, I have to use ignoreBuildErrors of Next.js.
Oh, that's a different problem. Type should be TagElement
. Probably an error in tools.
I've checked code in tools, it correctly uses TagElement
.
If item
in code above is not returned by tools, but is retrieved in other way, error is correct. item
can be tag, text or comment, but tagName
exists only on tag. So you need to check if item.type === 'tag'
Sorry, it's my cheerio script to parse html, there is no error before install @iconify/tools ๐
@cyberalien After investigation and try, I create a PR #36 for this, It passed the build:tools
and test:tools
scripts.
Thanks!
@cyberalien Is there any plan to release it?
Sure, but pull request is marked as draft. Is it ready?
Sure, but pull request is marked as draft. Is it ready?
I was waiting for you code review before, if no more comments, it's ready now ๐