TypeScript-DOM-lib-generator icon indicating copy to clipboard operation
TypeScript-DOM-lib-generator copied to clipboard

Fix Element.matches strict narrowing

Open cjc0013 opened this issue 6 months ago • 2 comments

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

cjc0013 avatar May 28 '26 02:05 cjc0013

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.

github-actions[bot] avatar May 28 '26 02:05 github-actions[bot]

@microsoft-github-policy-service agree

cjc0013 avatar May 28 '26 02:05 cjc0013