[Web API type definition issue] `exactOptionalPropertyTypes` makes working with most of the interfaces a nightmare
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- typescript
調査の方向性
まず、exactOptionalPropertyTypes を有効にした、提供されている Playground の例を使用して、生成された lib.dom.d.ts と RequestInit に関連する Web API 辞書の定義を調べます。Web IDL のルールで省略されたプロパティと同様に扱われる場合に、オプショナルな Web API プロパティが undefined を正しく受け入れ、生成された定義を壊さなければ完了です。
索引モデルが issue の本文から書いたものです。
説明
Summary
Optional fields in lib.dom.d.ts do not explicity have undefined in their types, which makes their construction needlessly difficult
Expected vs. Actual Behavior
Expected following code to just work:
function fetchUsers(params?: { signal?: AbortSignal | undefined }) {
return fetch("/api/v1/user/", { signal: params?.signal });
}
But instead the following error is shown:
Argument of type '{ signal: AbortSignal | undefined; }' is not assignable to parameter of type 'RequestInit' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
Types of property 'signal' are incompatible.
Type 'AbortSignal | undefined' is not assignable to type 'AbortSignal | null'.
Type 'undefined' is not assignable to type 'AbortSignal | null'. (2379)
Following is required to be done instead (let's pretend that RequestInit.signal cannot be set to null):
function fetchUsers(params?: { signal?: AbortSignal | undefined }) {
const init: RequestInit = {};
if (params?.signal) {
init.signal = params.signal;
}
return fetch("/api/v1/user/", init);
}
Playground Link
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
See https://webidl.spec.whatwg.org/#idl-dictionaries:
In the JavaScript binding, a value of undefined for the property corresponding to a dictionary member is treated the same as omitting that property.
I have not found a single | undefined on an optional interface field in the entire lib.dom.d.ts of Typescript 5.9.2.
- 主要言語
- TypeScript
- スター
- 740
- フォーク
- 474
- 平均マージ
- 3日 7時間
- マージ済み PR(30日)
- 14
環境構築
このプロジェクトの環境構築ファイルはまだ確認していません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/TypeScript-DOM-lib-generator のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
microsoft/TypeScript-DOM-lib-generator#2554 · コメント 6 件 ·
メンテナーはふだん 1 日以内に返信
-
lib.d.ts bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
microsoft/TypeScript-DOM-lib-generator#2485 ·
メンテナーはふだん 1 日以内に返信
-
lib.d.ts bug
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
microsoft/TypeScript-DOM-lib-generator#2154 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
lib.d.ts bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
microsoft/TypeScript-DOM-lib-generator#2107 · コメント 5 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
microsoft/TypeScript-DOM-lib-generator#1675 · コメント 2 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
microsoft/TypeScript-DOM-lib-generator の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
📕documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
db-ux-design-system/core-web#8343 ·
メンテナーはふだん 1 日以内に返信
-
enhancement triage/needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
heygen-com/hyperframes#4944 ·
メンテナーはふだん 1 日以内に返信
-
ai-driven-qa bug claude
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
linagora/twake-calendar-frontend#1493 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
material-extensions/vscode-material-icon-theme#3610 ·
メンテナーはふだん 2 日以内に返信