Created
July 22, 2020 05:11
-
-
Save mstssk/199c656fb81b7a66489b68955ca1fb5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 要素生成のヘルパ | |
* @param tagName 要素名 | |
* @param props プロパティ | |
*/ | |
function createElement< | |
K extends keyof HTMLElementTagNameMap, | |
AK extends keyof HTMLElementTagNameMap[K] | |
>( | |
tagName: K, | |
props: Record<AK, HTMLElementTagNameMap[K][Extract<AK, string>]> | |
): HTMLElementTagNameMap[K] { | |
const elem = document.createElement(tagName); | |
for (const key in props) { | |
elem[key] = props[key]; | |
} | |
return elem; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment