diff --git a/types/index.d.ts b/types/index.d.ts index 6c53546f9c..b299643f73 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -125,8 +125,8 @@ declare namespace cheerio { eq(index: number): Cheerio; - get(): any[]; - get(index: number): any; + get(): Element[]; + get(index: number): Element | undefined; index(): number; index(selector: string): number; diff --git a/types/index.test-d.ts b/types/index.test-d.ts index d2df7cbd7e..c11366e37b 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -1,4 +1,5 @@ import { expectType } from 'tsd'; +import { Element } from 'domhandler'; import cheerio from '..'; /* @@ -19,7 +20,7 @@ cheerio(html); cheerio('ul', html); cheerio('li', 'ul', html); -const $fromElement = cheerio.load($('ul').get(0)); +const $fromElement = cheerio.load($('ul').get(0) as Element); if ($fromElement('ul > li').length !== 3) { throw new Error( @@ -248,7 +249,7 @@ $el.eq(0).text(); $el.eq(-1).text(); // .get( [i] ) -$el.get(0).tagName; +$el.get(0)?.tagName; $el.get().length; // .index()