Skip to content

ElementListTagNameMap should be a mapped type derived from ElementTagNameMap #14782

Closed
@justinfagnani

Description

@justinfagnani

TypeScript Version: 2.2.1

Code

Right now there's some extra boilerplate when defining custom elements and augmenting dom.d.ts's tag name maps that could go away if mapped types were used more:

export class FooElement extends HTMLElement {}
customElements.define('foo', FooElement);

declare global {
  interface ElementTagNameMap {
    "foo": FooElement,
  }
  interface HTMLElementTagNameMap {
    "foo": FooElement,
  }
  interface ElementListTagNameMap {
    "foo": NodeListOf<FooElement>;
  }
}

It would be nice to only have to augment one interface, like so:

declare global {
  interface HTMLElementTagNameMap {
    "foo": FooElement,
  }
}

We could get closer if ElementListTagNameMap was defined like this:

type ElementListTagNameMap = {
  [P in keyof ElementTagNameMap]: NodeListOf<ElementTagNameMap[P]>;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions