Skip to content

FormDataLike iterator type is incorrect #19

Closed
@Ethan-Arrowood

Description

@Ethan-Arrowood

The iterator type for FormDataLike is incorrect / too restrictive (

[Symbol.iterator](): Generator<[string, FormDataEntryValue]>
). It uses Generator which makes methods throw and return required. But based on the spec, those two are optional for iterators (see here in MDN docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#throwexception) which are linked to in the source of FormDataLike itself.

I believe the types in undici are more accurate (https://github.com/nodejs/undici/blob/8050ec0224a51d44f776364820e6a16112fb4781/types/formdata.d.ts#L105 and https://github.com/nodejs/undici/blob/8050ec0224a51d44f776364820e6a16112fb4781/types/fetch.d.ts#L41-L47).

This is actually how I found this issue. I was trying to use the FormData object from Undici with the FormDataEncoder from this library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    TypeScriptTypeScript-related changes, like types or build its build infrastructurebugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions