Skip to content

ElementListTagNameMap should be a mapped type derived from ElementTagNameMap #14782

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

Closed
justinfagnani opened this issue Mar 22, 2017 · 2 comments
Labels
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this Suggestion An idea for TypeScript

Comments

@justinfagnani
Copy link

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]>;
}
@mhegazy mhegazy added Help Wanted You can do this Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Suggestion An idea for TypeScript labels Mar 22, 2017
@mhegazy mhegazy added this to the Community milestone Mar 22, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Mar 22, 2017

PRs welcomed. You can find more information about contributing lib.d.ts fixes at https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md#contributing-libdts-fixes.

@justinfagnani
Copy link
Author

Looks like it was fixed in microsoft/TypeScript-DOM-lib-generator@14029e6

@mhegazy mhegazy removed this from the Community milestone Apr 26, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants