Skip to content

Commit

Permalink
chore(types): Improve type for .get (#1759)
Browse files Browse the repository at this point in the history
  • Loading branch information
karlhorky committed Feb 27, 2021
1 parent ff76754 commit d706976
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expectType } from 'tsd';
import { Element } from 'domhandler';
import cheerio from '..';

/*
Expand All @@ -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(
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit d706976

Please sign in to comment.