Skip to content

URLSearchParams/Headers constructor also receives iterables including Map #19806

Open

Description

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

Activity

  1. saschanaz commented on Nov 7, 2017

    @saschanaz
    ContributorAuthor

    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)

  2. mhegazy commented on Nov 7, 2017

    @mhegazy
    Contributor

    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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptExperience EnhancementNoncontroversial enhancementsHelp WantedYou can do thisSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions