`FormData` implementation/types mismatch
まだ誰も着手していません。
- 主要言語
- JavaScript
- スター
- 122k
- フォーク
- 37.3k
- 平均マージ
- 4日 2時間
- マージ済み PR(30日)
- 283
説明
Version
v22.6.0
Platform
Darwin esmbp2023 23.5.0 Darwin Kernel Version 23.5.0: Wed May 1 20:17:33 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6031 arm64
Subsystem
Fetch
What steps will reproduce the bug?
Regarding FormData type definition (https://github.com/nodejs/node/blob/main/deps/undici/src/types/formdata.d.ts):
The majority of methods are defined as instance methods (e.g., append, set, getAll, etc.):
// EXAMPLE
export declare class FormData {
// ...
append (name: string, value: unknown, fileName?: string): void
// ...
}
But the following methods are defined as properties:
forEachkeysvaluesentriesSymbol.iterator
// EXAMPLE
export declare class FormData {
// ...
forEach: (
callbackfn: (value: FormDataEntryValue, key: string, iterable: FormData) => void,
thisArg?: unknown
) => void
// ...
}
This prevents extending those methods when extending FormData:
// EXAMPLE
class StrictFormData<T> extends FormData {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData/entries) */
entries = <TK extends keyof T & string>(): IterableIterator<
[TK, T[TK]]
> => {
// ERROR: TS2855: Class field entries defined by the parent class is not accessible in the child class via super.
return super.entries() as IterableIterator<[TK, T[TK]]>;
};
}
// EXAMPLE
class StrictFormData<T> extends FormData {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData/entries) */
// ERROR: TS2425: Class FormData defines instance member property entries, but extended class StrictFormData<T> defines it as instance member function.
entries<TK extends keyof T & string>(): IterableIterator<[TK, T[TK]]> {
// ERROR: TS2855: Class field entries defined by the parent class is not accessible in the child class via super.
return super.entries() as IterableIterator<[TK, T[TK]]>;
}
}
Is it a mistake in the type definitions?
When looking at the implementation (https://github.com/nodejs/node/blob/main/deps/undici/src/lib/web/fetch/formdata.js) I don't see any of those methods added, neither "statically", nor dynamically upon construction. I might be missing something because exactly those atypically defined methods are the ones that I cannot find in the implementation.
Thanks!
How often does it reproduce? Is there a required condition?
See above.
What is the expected behavior? Why is that the expected behavior?
See above.
What do you see instead?
See above.
Additional information
See above.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
deps/undici/src/types/formdata.d.ts と deps/undici/src/lib/web/fetch/formdata.js を比較し、forEach、keys、values、entries、Symbol.iterator に焦点を当てます。issue にある TypeScript のサブクラス化エラーを再現し、宣言または実装が意図された動作と異なるかどうかを判断します。FormData の型とランタイム動作に一貫性があり、報告された拡張ケースに対処できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, nodejs, typescript
- 領域
- api, backend
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 55/100