Skip to content

[k6] Fix Tester callback parameter type: Element → Selection#75191

Open
tsushanth wants to merge 1 commit into
DefinitelyTyped:masterfrom
tsushanth:fix/k6-html-tester-callback-type
Open

[k6] Fix Tester callback parameter type: Element → Selection#75191
tsushanth wants to merge 1 commit into
DefinitelyTyped:masterfrom
tsushanth:fix/k6-html-tester-callback-type

Conversation

@tsushanth

Copy link
Copy Markdown

Description

The Tester interface (the callback type for Selection.filter(), .is(), and .not()) declares its second parameter as Element:

export interface Tester {
    (index: number, element: Element): boolean;
}

At runtime, however, k6/html passes a Selection to these callbacks, not an Element. Code that calls Element-only methods (e.g. querySelector) inside the callback passes type-checking but throws at runtime with TypeError: Object has no member 'querySelector'.

The Mapper interface (for .map()) is already correctly typed as Selection. This PR aligns Tester to match.

Fixes the type mismatch documented in grafana/k6#6088.

Checklist

My changes:

  • Don't change the runtime behavior of any code.
  • Include tests (or were verified not to require tests).
  • Are marked as breaking changes (if applicable). N/A — this is a bug fix; code that currently passes tsc with the wrong type will still pass; code that was correct at runtime but wrong in types gets correct types.

The package I'm changing:

  • Is not a new package.
  • Provides the typings for an npm package (published: @types/k6).
  • Has had major version changes handled (the fix is version-independent).

The Tester interface (used by Selection.filter(), .is(), and .not())
declared its second parameter as Element, but k6 passes a Selection
at runtime. This caused code that called Element-only methods like
querySelector() to type-check but throw at runtime.

Mapper (the map() callback) was already correctly typed as Selection.
Align Tester to match.
@typescript-automation

typescript-automation Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

@tsushanth Thank you for submitting this PR!

This is a live comment that I will keep updated.

1 package in this PR

Code Reviews

Because this is a widely-used package, a DT maintainer will need to review it before it can be merged.

You can test the changes of this PR in the Playground.

Status

  • ✅ No merge conflicts
  • ✅ Continuous integration tests have passed
  • 🕐 Most recent commit is approved by a DT maintainer

Once every item on this list is checked, I'll ask you for permission to merge and publish the changes.


Diagnostic Information: What the bot saw about this PR
{
  "type": "info",
  "now": "-",
  "pr_number": 75191,
  "author": "tsushanth",
  "headCommitOid": "80c1c9948fd2db41e112ebe04f7b9750f3cf0754",
  "mergeBaseOid": "e186cd854fef1fbd5152877e78f9ab05743c226e",
  "lastPushDate": "2026-07-01T15:23:23.000Z",
  "lastActivityDate": "2026-07-01T15:23:23.000Z",
  "hasMergeConflict": false,
  "isFirstContribution": false,
  "tooManyFiles": false,
  "hugeChange": false,
  "tooManyCommits": false,
  "tooManyReviews": false,
  "popularityLevel": "Critical",
  "pkgInfo": [
    {
      "name": "k6",
      "kind": "edit",
      "files": [
        {
          "path": "types/k6/html/index.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/k6/test/html.ts",
          "kind": "test"
        }
      ],
      "owners": [
        "MStoykov",
        "codebien",
        "oleiade",
        "ankur22",
        "inancgumus",
        "joanlopez",
        "AgnesToulet",
        "szkiba"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Critical"
    }
  ],
  "reviews": [],
  "mainBotCommentID": 4856911440,
  "ciResult": "pass"
}

@typescript-automation

Copy link
Copy Markdown
Contributor

🔔 @mstoykov @codebien @oleiade @ankur22 @inancgumus @joanlopez @AgnesToulet @szkiba — please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

@typescript-automation typescript-automation Bot moved this to Waiting for Code Reviews in Pull Request Status Board Jul 1, 2026
@typescript-automation typescript-automation Bot moved this from Waiting for Code Reviews to Needs Maintainer Review in Pull Request Status Board Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Needs Maintainer Review

Development

Successfully merging this pull request may close these issues.

1 participant