Skip to content

Fix Element.matches strict narrowing#2487

Open
cjc0013 wants to merge 1 commit into
microsoft:mainfrom
cjc0013:fix-matches-strict-narrowing
Open

Fix Element.matches strict narrowing#2487
cjc0013 wants to merge 1 commit into
microsoft:mainfrom
cjc0013:fix-matches-strict-narrowing

Conversation

@cjc0013
Copy link
Copy Markdown

@cjc0013 cjc0013 commented May 28, 2026

Fixes microsoft/TypeScript#63497.

This follows the direction discussed in that issue: matches() should only act as a type guard when the selected tag's element type is a strict subtype of the current receiver type. For tags that map back to the same receiver type, it should still be accepted but return boolean, so the false branch does not narrow the receiver to never.

Summary

  • restrict Element.matches() type-predicate overloads to strict subtype matches
  • keep tag-name boolean overloads for same-type matches
  • regenerate DOM baselines
  • add a compile-only regression fixture for the reported false-branch never behavior

Validation

  • npm run generate
  • npm test
  • focused local TypeScript probe: the current baseline produced Property 'id' does not exist on type 'never'; the patched baseline compiles cleanly

@github-actions
Copy link
Copy Markdown
Contributor

Thanks for the PR!

This section of the codebase is owned by @saschanaz - if they write a comment saying "LGTM" then it will be merged.

@cjc0013
Copy link
Copy Markdown
Author

cjc0013 commented May 28, 2026

@microsoft-github-policy-service agree

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.

DOM: Element#matches() incorrectly narrows types

1 participant