Skip to content

fix: type the call and loop interceptor arguments as the hook's own - #288

Merged
alexander-akait merged 1 commit into
mainfrom
fix/typed-interceptor-arguments
Nov 13, 2026
Merged

alexander-akait merged 1 commit into
mainfrom
fix/typed-interceptor-arguments

Conversation

@alexander-akait

@alexander-akait alexander-akait commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Summary

An interceptor's call and loop are called with the hook's arguments: HookCodeFactory emits _interceptors[i].call(<args>). But they were typed (...args: any[]) => void, so any code that implements them got any. Both are now (...args: AsArray<T>) => void, the same arguments a tap gets.

const hook = new SyncHook<[string, number]>(["name", "count"]);
hook.intercept({
	call: (name, count) => {} // before: any, any — after: string, number
});

In webpack, this removes the untyped call interceptor in Compilation. It also surfaces one real mismatch: a typeof hook was handed a node typed only as Node, and webpack fixes that on its own side (webpack/webpack#23309).

HookMap's key stays any. A key type parameter defaulting to any would add any to every HookMap<H> type, and a string or unknown default would break existing factories and interceptors that annotate their key.

What kind of change does this PR introduce?

fix (types)

Did you add tests for your changes?

No. Only tapable.d.ts changes, and the repository has no type tests: npm run lint:types checks lib/** only, so it doesn't cover this file. I verified the declarations two other ways:

  • A consumer file type-checked against them. On a SyncHook<[string, number]>, call: (name, count) => now gets string and number, and loop: (...args) gets [string, number]. A call whose parameter has the wrong type is rejected. AsyncSeriesHook, SyncLoopHook and (...args) => interceptors still type-check. With the current declarations, the same file gets any and accepts the wrong type.
  • webpack type-checked against them. It passes once its typeof hook node is typed (refactor: type rule effect values, the typeof hook's node and the statement-type hook maps webpack#23309).

npm run lint and npm test pass.

Does this PR introduce a breaking change?

No for runtime. For types, an interceptor call/loop that declares parameter types which don't match the hook's arguments now fails to type-check. Those parameters were already wrong at runtime. Interceptors written as (...args) => or with matching types are unaffected.

If relevant, what needs to be documented once your changes are merged or what have you already documented?

n/a

Use of AI

Written with Claude Code (investigation, implementation, verification against webpack and this description), directed and reviewed by me.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HArJAXZagrHVVNLZZk9soh

@changeset-bot

changeset-bot Bot commented Nov 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a563401

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
tapable Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 625be97d-9a35-4476-91a8-46b5b768fd3f
Commits

Reviewing files that changed from the base of the PR and between a563401 and 3ba2045.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

Walkthrough

The HookInterceptor interface now types the call and loop callback arguments as AsArray<T> instead of any[]. A patch changeset documents the update.

Merge Risk: Minimal · previous review a5634

This is a type-only change to the interceptor call and loop callbacks, with no runtime effect. Only TypeScript users who define context-enabled interceptors outside an object literal could see a new type error, a narrow case with a simple workaround. No merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title says the call and loop interceptor arguments are now typed as the hook's own arguments. The raw summary and objectives confirm that tapable.d.ts changes HookInterceptor call and loop from (.…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title says the call and loop interceptor arguments are now typed as the hook's own arguments. The raw summary and objectives confirm that tapable.d.ts changes HookInterceptor call and loop from (...args: any[]) to (...args: AsArray<T>), and that a patch changeset is added. The title names the main change and fits the changeset.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nitpick comments: 1

tapable.d.ts: 1

48-49: Trivial · Maintainability & Code Quality · Poor tradeoff

Add type-level tests for the published call and loop declarations.

lint:types runs tsc --noEmit over lib/**/* only, and tapable.d.ts is not included. This PR changes the argument types of call and loop in tapable.d.ts, and no check in the repository exercises those types. A later change that breaks argument inference or accepts an invalid callback signature would pass npm run lint and npm test.

Add a small consumer type test that covers both call and loop. It should check the inferred argument types and reject a mismatched callback signature. The repository has no type-test tooling yet, so this also needs a new tsconfig target and a check script.

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0d337237-d575-4e17-9884-a52afabc046b
Commits

Reviewing files that changed from the base of the PR and between e355aeb and a563401.

Files selected for processing: 2

  • .changeset/typed-interceptor-arguments.md
  • tapable.d.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@codecov

codecov Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.25%. Comparing base (9ada8a4) to head (3ba2045).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #288   +/-   ##
=======================================
  Coverage   99.25%   99.25%           
=======================================
  Files          15       15           
  Lines         805      805           
  Branches      140      140           
=======================================
  Hits          799      799           
  Misses          6        6           
Flag Coverage Δ
integration 99.25% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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
Copy Markdown
Member Author

The benchmark failure isn't from this PR. It fails the same way on main since #286: CodSpeedHQ/action v4.19.1 exits with Unsupported system on the current ubuntu-latest image before any benchmark runs. #289 bumps the action to v5.6.3.


Generated by Claude Code

An interceptor's `call` and `loop` are called with the hook's arguments,
but were typed `(...args: any[]) => void`, so whatever read them was untyped.
@alexander-akait
alexander-akait force-pushed the fix/typed-interceptor-arguments branch from a563401 to 3ba2045 Compare November 13, 2026 10:48
@codspeed

codspeed Bot commented Nov 13, 2026

Copy link
Copy Markdown

Hooray! CodSpeed harness just leveled up!

The base and head of this comparison were measured with different runner settings, so their benchmark values are not directly comparable.

What changed between base and head:

Re-run the base with the same settings to get a valid performance comparison.


Comparing fix/typed-interceptor-arguments (3ba2045) with main (10f5a28)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (9ada8a4) during the generation of this report, so 10f5a28 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@alexander-akait
alexander-akait merged commit 25d4f1b into main Nov 13, 2026
36 checks passed
@alexander-akait
alexander-akait deleted the fix/typed-interceptor-arguments branch November 13, 2026 13:42
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.

1 participant