Skip to content

URLSearchParams should accept an iterable #741

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
fregante opened this issue Jul 23, 2019 · 3 comments
Open

URLSearchParams should accept an iterable #741

fregante opened this issue Jul 23, 2019 · 3 comments

Comments

@fregante
Copy link

This works in the browser, but the TS definition doesn't allow it:

new URLSearchParams(new FormData(document.querySelector('form')));

The type is currently:

declare var URLSearchParams: {
    prototype: URLSearchParams;
    new(init?: string[][] | Record<string, string> | string | URLSearchParams): URLSearchParams;
};

The specification says that it should accept a "sequence", not specifically an array https://url.spec.whatwg.org/#concept-urlsearchparams-new

@saschanaz
Copy link
Contributor

Currently the blocker is #222, because

  1. We have to emit a new signature with an iterable argument in *.iterable.d.ts (and keep the current one for es5 support).
  2. The current declare var pattern cannot be extended, so we can't add signatures via *.iterable.d.ts.

@Ryan1729
Copy link

The current definition of URLSearchParams is also missing some methods that return iterators. Specifically these ones (copied from @types/node):

    entries(): IterableIterator<[string, string]>;
    keys(): IterableIterator<string>;
    values(): IterableIterator<string>;

I suppose those are probably blocked on the same issue.

@saschanaz
Copy link
Contributor

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants