Skip to content
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

The Cheerio interface is not exported in the type definitions #1540

Closed
sk-pub opened this issue Nov 18, 2020 · 4 comments · Fixed by #1682
Closed

The Cheerio interface is not exported in the type definitions #1540

sk-pub opened this issue Nov 18, 2020 · 4 comments · Fixed by #1682

Comments

@sk-pub
Copy link

sk-pub commented Nov 18, 2020

See https://github.com/cheeriojs/cheerio/blob/v1.0.0/types/index.d.ts
The interface Cheerio is declared but not exported. It leads to TS compilation errors in projects, that need it. E.G. vuejs/vue-test-utils#1737

@fb55
Copy link
Member

fb55 commented Nov 19, 2020

Feel free to open a PR to add this!

@fb55
Copy link
Member

fb55 commented Dec 22, 2020

Looking at your link, it seems like the issue is that we export a value type. If all that's needed is a typeof, the additional export does not really seem worth it.

@fb55 fb55 closed this as completed Dec 22, 2020
@lynxtaa
Copy link

lynxtaa commented Dec 28, 2020

Looking at your link, it seems like the issue is that we export a value type. If all that's needed is a typeof, the additional export does not really seem worth it.

Consider this code when using cheerio@1.0.0-rc.3:

function getTrimmedText(el: cheerio.Cheerio): string {
  return el.text().trim()
}

const $ = cheerio.load(html)
const trimmedText = getTrimmedText($('#text'))

How can I type an argument for a function getTrimmedText in cheerio@1.0.0-rc.5? typeof cheerio will return cheerio.CheerioAPI which is not the same as cheerio.Cheerio.

I think this issue should be reopened.

@lynxtaa
Copy link

lynxtaa commented Dec 28, 2020

After further investigation I think declaring type Cheerio = ReturnType<typeof cheerio> works. But it's not obvious in comparison with @types/cheerio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants