我试图找到将接口转换为普通对象的方法。默认情况下,打字稿会阻止它,因此通常会得到'XXX' only refers to a type, but is being used as a value here.
但是这时我确实需要找到它。如今,我正在构建一个小型的react-cloned库,像react一样希望支持预定义的标签。
在打字稿中,它具有默认的HTMLElementTagNameMap
{
"a": HTMLAnchorElement;
"abbr": HTMLElement;
"address": HTMLElement;
"applet": HTMLAppletElement;
...
}
So Here's the thing, I want to make an object like this. please help me.
const D: HTML each Type = Object.entries(//HTMLElementTagNameMap need to be converted).reduce<{[tagName] : HTML each Type]}>(
(acc, tagName) =>
(acc[tagName] = (
attributes: IAttribute<T>,
...childNodes: (HTMLElement | Component<any, any>)[]
) => createElement<T>(tagName, attributes, ...childNodes)),
{}
);