From 5f2e9c322ec7d63e0dd0f7c5d587c9074f3158c3 Mon Sep 17 00:00:00 2001 From: Max Ma Date: Tue, 12 Jan 2021 23:41:04 +0800 Subject: [PATCH] fix(types): Fix AttrFunction arguments (#1669) * fix(typing): AttrFunction * test(types): AttrFunction * chore(lint): AttrFunction prettier --- types/index.d.ts | 2 +- types/index.test-d.ts | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index e5c8957f79..5620dbeab7 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -2,7 +2,7 @@ import { Document, Element, DomHandlerOptions } from 'domhandler'; import { ParserOptions } from 'htmlparser2'; declare namespace cheerio { - type AttrFunction = (el: Element, i: number, currentValue: string) => any; + type AttrFunction = (this: Element, i: number, currentValue: string) => any; interface Cheerio { // Document References diff --git a/types/index.test-d.ts b/types/index.test-d.ts index bfed0143c2..c86fcbfe0c 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -81,8 +81,16 @@ $el.cheerio; $el.attr(); $el.attr('id'); $el.attr('id', 'favorite').html(); -$el.attr('id', (el, i, attr) => el.tagName + i * 2 + attr).html(); -$el.attr('id', (el) => el.tagName).html(); +$el + .attr('id', function (i, attr) { + return this.tagName + i * 2 + attr; + }) + .html(); +$el + .attr('id', function () { + return this.tagName; + }) + .html(); $el.attr({ id: 'uniq', class: 'big' }).html(); $multiEl.prop('foo') === undefined;