I am trying to convert this JavaScript code from atom/etch to TypeScript without breaking the public API.
It defines both a dom-function and a dom-array of functions (both have the same name dom):
// called by the following loop
function dom (tag, props, ...children) {
// ...
}
const HTML_TAGS = [
'a', 'abbr'] // ... has more elements though
// similarly SVG-Tags is defined
// finds the array of functions
for (const tagName of HTML_TAGS) {
dom[tagName] = (props, ...children) => {
return dom(tagName, props, ...children)
}
}
for (const tagName of SVG_TAGS) {
dom[tagName] = (props, ...children) => {
return dom(tagName, props, ...children)
}
}
module.exports = dom
What is the equivalent TypeScript version of this?
Other packages use dom like dom.a(tag, props, childern) an example, or using @jsx etch.dom an example
By running dts-gen, I get a namespace called dom which contains all the functions defined inside the for-loop.
export namespace dom {
function a(props: any, children: any): any;
function abbr(props: any, children: any): any;
//...
}
Here is my branch.