Skip to content

fix: allow removing all wildcard handlers in TypeScript - #222

Open
xiehuanyi wants to merge 1 commit into
developit:mainfrom
xiehuanyi:fix/wildcard-off-optional-handler-20261011
Open

xiehuanyi wants to merge 1 commit into
developit:mainfrom
xiehuanyi:fix/wildcard-off-optional-handler-20261011

Conversation

@xiehuanyi

Copy link
Copy Markdown

What is the purpose of this pull request?

  • Bug fix

What changes did you make?

mitt<{ foo: string }>().off('*') removes every wildcard listener at runtime, but TypeScript rejects it because the wildcard overload requires a handler. Make that handler optional, matching the documented behavior and the maintainer's example in #150.

Add strict type checks for an omitted handler and explicit undefined, plus a runtime check that named listeners remain registered. Existing checks that reject the wrong wildcard callback type remain in place.

Validation

The new type calls fail on the original declaration with TS2345/TS2769. After the change, npm run bundle and the full npm test suite pass on Node 18 (20 runtime tests, strict type checks and lint). The repository's existing esm loader is incompatible with the local Node 22 runtime, so the suite was run on Node 18 with compatible Node type declarations. No package changes are included.

Is there anything you'd like reviewers to focus on?

The wildcard overload now permits the same handler omission as the named-event overload.

Does this PR introduce a breaking change?

No; it expands the type declaration to accept an existing runtime operation.

Copilot AI balanced review requested due to automatic review settings October 11, 2026 12:16

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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