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

How to use cheerio interface #1696

Closed
keyiis opened this issue Jan 23, 2021 · 6 comments
Closed

How to use cheerio interface #1696

keyiis opened this issue Jan 23, 2021 · 6 comments

Comments

@keyiis
Copy link

keyiis commented Jan 23, 2021

I used cheerio in typescript ,i need pass cheerio.Root Object in different method

import * as cheerio from 'cheerio';
async function parse(html:string){
        let $ = cheerio.load(html);
        methodA($);
 }
function methodA($:cheerio.Root){
     ......
}

but vscode prompted an error
image
I find Root type in index.d.ts
image

@keyiis keyiis changed the title How to pass use cheerio interfacec How to use cheerio interfacec Jan 23, 2021
@keyiis keyiis changed the title How to use cheerio interfacec How to use cheerio interface Jan 23, 2021
@5saviahv
Copy link
Contributor

5saviahv commented Jan 23, 2021

You can check #1649 and #1540 also #1682

@keyiis
Copy link
Author

keyiis commented Jan 23, 2021

@5saviahv i tried #1682 ,but still not work
tsconfig.json

{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "moduleResolution": "node",
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "esModuleInterop":true,
        "removeComments": true,
        "skipLibCheck":true,
        "sourceMap": true,
        "declaration": false,
        "pretty": true,
        "lib": [
            "es2015",
            "es2016",
            "es2017",
            "es2019"
        ]
    }
}

@keyiis
Copy link
Author

keyiis commented Jan 23, 2021

i installed @types/cheerio,it works. so i think the root cause is not export interface in index.d.ts.

@dominik-korsa
Copy link
Contributor

The idea of bundling types is so you don't have to install a package from DefinitelyTyped (@types)

@5saviahv
Copy link
Contributor

True, bundling types also gives you opportunity to give version specific definitions. I believe @types gives you currently types for v0.22.

@5saviahv
Copy link
Contributor

5saviahv commented Jan 25, 2021

Like @keyiis mention in #1682 it is solved

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

No branches or pull requests

3 participants