Skip to content

Instantly share code, notes, and snippets.

@atmin
Created May 30, 2020 09:05
Show Gist options
  • Save atmin/b4fbcd4bec18feea27adf0cd6a3b3d5d to your computer and use it in GitHub Desktop.
Save atmin/b4fbcd4bec18feea27adf0cd6a3b3d5d to your computer and use it in GitHub Desktop.
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