Skip to content

Instantly share code, notes, and snippets.

Created May 30, 2020
What would you like to do?
function dom<T extends HTMLElement>(
name: string,
props: { [key in keyof T]?: any } = {},
children: Array<HTMLElement> = []
): T {
const result = document.createElement(name);
Object.entries(props).forEach(([name, prop]) => (result[name] = prop));
children.forEach(child => result.append(child));
return result as T;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment