Microsoft/TypeScript
GitHub ã§èŠãDOM: `Element#matches()` incorrectly narrows types
Open
#63,497 opened on 2026幎5æ20æ¥
Domain: lib.d.tsHelp Wanted
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
ð Search Terms
element matches narrow never
ð Version & Regression Information
- This changed between versions 5.9.3 and 6.0.3
⯠Playground Link
ð» Code
declare let element: HTMLElement;
!element.matches( 'dt' ) && element.matches( 'dd' )
ð Actual behavior
element.matches( 'dd' ) throws a Property 'matches' does not exist on type 'never' compilation error.
ð Expected behavior
element.matches( 'dd' ) does not throw any error.
Additional information about the issue
element.matches( 'dt' ) uses the following overload:
matches<K extends keyof HTMLElementTagNameMap>(selectors: K): this is HTMLElementTagNameMap[K];
The return type of element.matches( 'dt' ) is then this is HTMLElementTagNameMap['dt'] that maps to this is HTMLElement.
Since this is HTMLElement:
- When false, the type of
elementisHTMLElement(not narrowed further). - When false, the type of
elementisnever.