microsoft / microsoft/TypeScript
Event of type `"error"` incorrectly typed as ErrorEvent even when it's not actually ErrorEvent in practice
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Bug Report
🔎 Search Terms
ErrorEvent error capture
🕗 Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about events
⏯ Playground Link
Playground link with relevant code
💻 Code
const scriptElement = document.createElement('script');
scriptElement.addEventListener('error', event => {
console.log(`1. script element error event constructor: ${event.constructor.name}`);
});
scriptElement.src = 'https://example.com/nonExistentScript.js';
const linkElement = document.createElement('link');
linkElement.addEventListener('error', event => {
console.log(`2. link element error event constructor: ${event.constructor.name}`);
});
linkElement.rel = 'stylesheet';
linkElement.href = 'https://example.com/nonExistentStylesheet.css';
window.addEventListener('error', event => {
console.log(`3. window error event constructor: ${event.constructor.name}`);
});
window.addEventListener('error', event => {
console.log(`4. window error (with capture) event constructor: ${event.constructor.name}`);
}, {
capture: true
});
document.head.appendChild(scriptElement);
document.head.appendChild(linkElement);
throw new Error('Uncaught Error');
🙁 Actual behavior
For the above code, the TypeScript compiler types each event callback parameter as ErrorEvent, even though that's not always the type at runtime
Note that the linked playground doesn't show the log messages for the uncaught Error case; here's the full log output:
3. window error event constructor: ErrorEvent
4. window error (with capture) event constructor: ErrorEvent
4. window error (with capture) event constructor: Event
2. link element error event constructor: Event
4. window error (with capture) event constructor: Event
1. script element error event constructor: Event
🙂 Expected behavior
I don't know enough about the DOM "error" event to know what a complete solution would be, but ideally, in the code above, I guess the type for event would be:
EventEventErrorEvent(assumingwindownon-capture event dispatches of type"error"are always ErrorEvent, which I don't know)ErrorEvent | Event
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされている TypeScript Playground と、例で関係する DOM の "error" イベントリスナーの型定義から始めます。推論されたコールバックパラメーターの型を、script、link、window イベントについて実行時にログ出力されたコンストラクターと比較し、その結果の型がこれらのケースを正確に表していることを確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, typescript
- 領域
- frontend, web-dev
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100