Skip to content

Commit

Permalink
fix(types): Fix AttrFunction arguments (#1669)
Browse files Browse the repository at this point in the history
* fix(typing): AttrFunction

* test(types): AttrFunction

* chore(lint): AttrFunction prettier
  • Loading branch information
maxma241 authored Jan 12, 2021
1 parent a336301 commit 5f2e9c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5f2e9c3

Please sign in to comment.