Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

[Web API type definition issue] lib.dom `options` parameter for `MutationObserver#observe` should not be optional

未關閉 適合新手
#2,566 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
62/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
typescript
領域
api

研究方向

該 issue 要求 MutationObserver#observe 將其 options 參數設為必需,這樣在沒有該參數的情況下呼叫 observe(el) 會成為型別錯誤,與 MDN 引文中描述的執行時 TypeError 一致。首先找到該簽章是在哪裡產生的:查看產生的 lib.dom.d.ts 中針對 MutationObserver.observe 的宣告,並追溯回此產生器中定義它的輸入檔,然後更新該來源檔,而不是產生的輸出。完成意味著重新執行產生器,observe(el) 會回報錯誤,而 observe(el, { childList: true }) 仍然可以編譯。

由索引模型根據 Issue 內容生成。

描述

lib.d.ts bug
Summary

Not passing options, or passing options without minimum requirements, is an error (type error at runtime)

Expected vs. Actual Behavior

Expected:

Calling new MutationObserver(fn).observe(el) without a second options argument should show a type error because options are required.

Actual:

There is no type error. We discover the error at runtime.

Playground Link

https://www.typescriptlang.org/play/?#code/MYewdgzgLgBAtiGBeGYCmB3GBZArlAQygEtwB5AIwjQCcA3WgCkYEpkA+GAbwF8WAofgHohMAAJQIAWjQAPAA5pgUGTRogaMKAAs0MaqDA0AJjAI0A5rjhowsYhBg00AR1zFnpgsFAniYCy1ECEVgADoYADkQWHkCCAh-QOJYHXUMRwIYABUAT0UAUTUNfgQwkCpaBkZjEGBrWygwihBjXJYgA

Browser Support
  • This API is supported in at least two major browser engines (not two Chromium-based browsers).
Have Tried The Latest Releases
  • This issue applies to the latest release of TypeScript.
  • This issue applies to the latest release of @types/web.
Additional Context

From MDN docs:

An object providing options that describe which DOM mutations should be reported to mutationObserver's callback. At a minimum, one of childList, attributes, and/or characterData must be true when you call observe(). Otherwise, a TypeError exception will be thrown.

主要語言
TypeScript
星號
741
分支
475
平均合併
6 天 10 小時
30 天內合併 PR
6

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

microsoft/TypeScript-DOM-lib-generator 的其他 Issue

查看 microsoft/TypeScript-DOM-lib-generator 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。