Closed
Description
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]>;
}