`FormData` implementation/types mismatch
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.4k
- 平均合并
- 4 天 3 小时
- 30 天内合并 PR
- 272
描述
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 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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