microsoft / microsoft/TypeScript
DOM: `Element#matches()` incorrectly narrows types
オープン
まだ誰も着手していません。
Domain: lib.d.ts
Help Wanted
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
🔎 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.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされた TypeScript Playground の例から始め、issue に示されている Element#matches のオーバーロードを調べ、否定チェックの後に型述語が HTMLElement をどのように絞り込むかを追跡します。2 回目の element.matches('dd') 呼び出しが、Property 'matches' does not exist on type 'never' エラーなしでコンパイルできれば、issue は完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 活発
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 52/100