Skip to content

Instantly share code, notes, and snippets.

@ddprrt ddprrt/CreatedElement.ts Secret
Created Jul 15, 2019

Embed
What would you like to do?
Map types
type AllElements = {
'a': HTMLAnchorElement;
'div': HTMLDivElement;
'span': HTMLSpanElement;
'ul': HTMLUListElement;
'title': HTMLTitleElement;
'textarea': HTMLTextAreaElement;
'template': HTMLTemplateElement;
'tfoot': HTMLTableSectionElement;
'thead': HTMLTableSectionElement;
'tbody': HTMLTableSectionElement;
'tr': HTMLTableRowElement;
'table': HTMLTableElement;
'col': HTMLTableColElement;
'colgroup': HTMLTableColElement;
'th': HTMLTableHeaderCellElement;
'td': HTMLTableDataCellElement;
'caption': HTMLTableCaptionElement;
'style': HTMLStyleElement;
'select': HTMLSelectElement;
'script': HTMLScriptElement;
'blockquote': HTMLQuoteElement;
'q': HTMLQuoteElement;
'progress': HTMLProgressElement;
'pre': HTMLPreElement;
'param': HTMLParamElement;
'p': HTMLParagraphElement;
'output': HTMLOutputElement;
'option': HTMLOptionElement;
'optgroup': HTMLOptGroupElement;
'object': HTMLObjectElement;
'ol': HTMLOListElement;
'ins': HTMLModElement;
'del': HTMLModElement;
'meter': HTMLMeterElement;
'meta': HTMLMetaElement;
'marquee': HTMLMarqueeElement;
'map': HTMLMapElement;
'video': HTMLVideoElement;
'audio': HTMLAudioElement;
'link': HTMLLinkElement;
'legend': HTMLLegendElement;
'label': HTMLLabelElement;
'li': HTMLLIElement;
'input': HTMLInputElement;
'img': HTMLImageElement;
'iframe': HTMLIFrameElement;
'html': HTMLHtmlElement;
'h1': HTMLHeadingElement;
'h2': HTMLHeadingElement;
'h3': HTMLHeadingElement;
'h4': HTMLHeadingElement;
'h5': HTMLHeadingElement;
'h6': HTMLHeadingElement;
'head': HTMLHeadElement;
'hr': HTMLHRElement;
'frameset': HTMLFrameSetElement;
'frame': HTMLFrameElement;
'form': HTMLFormElement;
'font': HTMLFontElement;
'fieldset': HTMLFieldSetElement;
'embed': HTMLEmbedElement;
'datalist': HTMLDataListElement;
'dl': HTMLDListElement;
'canvas': HTMLCanvasElement;
'button': HTMLButtonElement;
'body': HTMLBodyElement;
'base': HTMLBaseElement;
'br': HTMLBRElement;
'area': HTMLAreaElement
}
type CreatedHTMLElement<T extends keyof AllElements> = AllElements[T];
type CreatedElement<T extends string> =
T extends keyof AllElements ? CreatedHTMLElement<T> : HTMLElement;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.