Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

URLSearchParams/Headers constructor also receives iterables including Map #19806

Open
saschanaz opened this issue Nov 7, 2017 · 2 comments
Open
Labels
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Experience Enhancement Noncontroversial enhancements Help Wanted You can do this Suggestion An idea for TypeScript
Milestone

Comments

@saschanaz
Copy link
Contributor

saschanaz commented Nov 7, 2017

TypeScript Version: master

Code

new Headers(new Map([['abc', 'bcd']])).get('abc')
new Headers({ [Symbol.iterator]() { return new Map([['abc', 'bcd']]).entries() } }).get('abc')

Expected behavior: Both returns bcd so should pass without errors

Actual behavior: 'not assignable' error

@saschanaz
Copy link
Contributor Author

saschanaz commented Nov 7, 2017

I think this will do the work for ES2015+:

type Record<K, V> = { [Symbol.iterator](): IterableIterator<[K, V]> } | { [x: K]: V };

But we cannot make this compatible with ES5 as DOM constructor types cannot be extended.

PS: (This is wrong, the sequence type should be processed instead)

@mhegazy
Copy link
Contributor

mhegazy commented Nov 7, 2017

I guess if you want this to work everywhere, you need:

  • a new global type for Headers constructor
  • an overload in lib.dom.iterable.d.ts to add overloads with Symbol.Iterator on them.

@mhegazy mhegazy added Suggestion An idea for TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript labels Nov 7, 2017
OliverJAsh added a commit to OliverJAsh/TypeScript that referenced this issue Jan 22, 2018
@weswigham weswigham added In Discussion Not yet reached consensus Help Wanted You can do this labels Nov 6, 2018
@weswigham weswigham added this to the Community milestone Nov 6, 2018
@RyanCavanaugh RyanCavanaugh modified the milestones: Community, Backlog Mar 7, 2019
@RyanCavanaugh RyanCavanaugh added Experience Enhancement Noncontroversial enhancements and removed In Discussion Not yet reached consensus labels Jul 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Experience Enhancement Noncontroversial enhancements Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants