Skip to content

Commit d6810a4

Browse files
committed
prevent Component.from template literal expansion in docs
1 parent ada4797 commit d6810a4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ type ElementToTagName<T extends HTMLElement> = {
2020
[K in keyof HTMLElementTagNameMap]: HTMLElementTagNameMap[K] extends T ? K : never
2121
}[keyof HTMLElementTagNameMap];
2222

23+
type HtmlTagString<T extends HTMLElement> =
24+
`<${{ [K in keyof HTMLElementTagNameMap]: HTMLElementTagNameMap[K] extends T ? K : never }[keyof HTMLElementTagNameMap]}>${string}`
25+
| `<${{ [K in keyof HTMLElementTagNameMap]: HTMLElementTagNameMap[K] extends T ? K : never }[keyof HTMLElementTagNameMap]} ${string}`;
26+
2327
/**
2428
* An {@link !HTMLElement} component.
2529
*
@@ -44,7 +48,7 @@ export class Component<T extends HTMLElement = HTMLElement> extends BaseComponen
4448
*
4549
* Note: only the first child of the HTML code will be used.
4650
*/
47-
public static from<T extends HTMLElement = HTMLElement>(html: `<${ElementToTagName<T>}${">" | " "}${string}`) {
51+
public static from<T extends HTMLElement = HTMLElement>(html: HtmlTagString<T>) {
4852
return new Component<T>(document.createRange().createContextualFragment(html).children[0] as T);
4953
}
5054

0 commit comments

Comments
 (0)