`FormData` implementation/types mismatch
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- JavaScript
- Estrellas
- 122k
- Forks
- 37.3k
- Merge medio
- 4 d 2 h
- PR fusionados (30 d)
- 283
Descripción
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Compara deps/undici/src/types/formdata.d.ts con deps/undici/src/lib/web/fetch/formdata.js, centrándote en forEach, keys, values, entries y Symbol.iterator. Reproduce los errores de TypeScript al crear subclases indicados en el issue y determina si las declaraciones o la implementación difieren del comportamiento previsto. Se considera terminado cuando los tipos de FormData y el comportamiento en tiempo de ejecución son coherentes y el caso de extensión notificado está resuelto.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript, nodejs, typescript
- Área
- api, backend
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Tranquilo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 55/100