Cheerio: The Cheerio interface is not exported in the type definitions

Created on 18 Nov 2020  路  4Comments  路  Source: cheeriojs/cheerio

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. https://github.com/vuejs/vue-test-utils/issues/1737

馃挕 Feature

Most helpful comment

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

All 4 comments

Feel free to open a PR to add this!

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.

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 [email protected]:

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 [email protected]? typeof cheerio will return cheerio.CheerioAPI which is not the same as cheerio.Cheerio.

I think this issue should be reopened.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rajkumarpb picture rajkumarpb  路  3Comments

M3kH picture M3kH  路  4Comments

dandv picture dandv  路  5Comments

askie picture askie  路  4Comments

tndev picture tndev  路  4Comments