From d706976cb085efa28ab43f39acbcaa74da514632 Mon Sep 17 00:00:00 2001 From: Karl Horky Date: Sat, 27 Feb 2021 21:04:53 +0100 Subject: [PATCH] chore(types): Improve type for `.get` (#1759) --- types/index.d.ts | 4 ++-- types/index.test-d.ts | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) 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()