Skip to content

Conversation

atomiechen
Copy link
Contributor

@atomiechen atomiechen commented Aug 27, 2025

Overview

This PR fixes an incorrect type definition in ContentScriptContext.addEventListener with Document targets.
Previously, the method signature defined the parameter as:

addEventListener<TType extends keyof DocumentEventMap>(
  target: Document,
  type: keyof DocumentEventMap,
  handler: (event: DocumentEventMap[TType]) => void,
  options?: AddEventListenerOptions,
): void;

Here, type was hardcoded as keyof DocumentEventMap instead of using the generic TType.
This caused type inference issues when registering event listeners, making TypeScript report incompatibility errors (e.g., with click handlers typed as PointerEvent).

The fix updates the method signature to:

addEventListener<TType extends keyof DocumentEventMap>(
  target: Document,
  type: TType,
  handler: (event: DocumentEventMap[TType]) => void,
  options?: AddEventListenerOptions,
): void;

This ensures proper type inference for the event handler parameter.

Manual Testing

  1. Create a content script using ctx.addEventListener with different event types:

    ctx.addEventListener(document, "click", (e) => {
      e.clientX;  // ✅ properly inferred as PointerEvent
    });
    
    ctx.addEventListener(document, "click", (e: PointerEvent) => {  // ✅ No error of "No overload matches this call."
      ...
    });
  2. Confirm that TypeScript correctly infers the handler parameter type depending on the event name.

Related Issue

N/A.

Copy link

netlify bot commented Aug 27, 2025

Deploy Preview for creative-fairy-df92c4 ready!

Name Link
🔨 Latest commit c1680a0
🔍 Latest deploy log https://app.netlify.com/projects/creative-fairy-df92c4/deploys/68b8406a56e42800080d5422
😎 Deploy Preview https://deploy-preview-1863--creative-fairy-df92c4.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Member

@aklinker1 aklinker1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link

codecov bot commented Sep 3, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.86%. Comparing base (d1c50ab) to head (c1680a0).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1863      +/-   ##
==========================================
- Coverage   80.97%   80.86%   -0.11%     
==========================================
  Files         131      131              
  Lines        6679     6679              
  Branches     1092     1093       +1     
==========================================
- Hits         5408     5401       -7     
- Misses       1260     1267       +7     
  Partials       11       11              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

pkg-pr-new bot commented Sep 3, 2025

Open in StackBlitz

@wxt-dev/analytics

npm i https://pkg.pr.new/@wxt-dev/analytics@1863

@wxt-dev/auto-icons

npm i https://pkg.pr.new/@wxt-dev/auto-icons@1863

@wxt-dev/browser

npm i https://pkg.pr.new/@wxt-dev/browser@1863

@wxt-dev/i18n

npm i https://pkg.pr.new/@wxt-dev/i18n@1863

@wxt-dev/module-react

npm i https://pkg.pr.new/@wxt-dev/module-react@1863

@wxt-dev/module-solid

npm i https://pkg.pr.new/@wxt-dev/module-solid@1863

@wxt-dev/module-svelte

npm i https://pkg.pr.new/@wxt-dev/module-svelte@1863

@wxt-dev/module-vue

npm i https://pkg.pr.new/@wxt-dev/module-vue@1863

@wxt-dev/runner

npm i https://pkg.pr.new/@wxt-dev/runner@1863

@wxt-dev/storage

npm i https://pkg.pr.new/@wxt-dev/storage@1863

@wxt-dev/unocss

npm i https://pkg.pr.new/@wxt-dev/unocss@1863

@wxt-dev/webextension-polyfill

npm i https://pkg.pr.new/@wxt-dev/webextension-polyfill@1863

wxt

npm i https://pkg.pr.new/wxt@1863

commit: c1680a0

@aklinker1 aklinker1 merged commit 7c59e9d into wxt-dev:main Sep 3, 2025
18 checks passed
Copy link
Contributor

github-actions bot commented Sep 3, 2025

Thanks for helping make WXT better!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants