Unable to get typescript typings to work for custom html elements #135
-
I may be overlooking something, but I'm stuck so would appreciate any help :) I'm trying to use return unified()
.use(remarkParse)
.use(remarkGfm)
.use(remarkRehype)
.use(rehypeRaw)
.use(rehypeReact, {
createElement: createElement,
Fragment,
components: {
"custom-element": CustomComponent
},
});
const CustomComponent: React.FC = () => {
return <div/>;
}; Typescript isn't happy with this as components are defined to only take in JSX.intrinsic types: components?: Partial<{
[TagName in keyof JSX.IntrinsicElements]:
| keyof JSX.IntrinsicElements
| ComponentType<JSX.IntrinsicElements[TagName]>
}> and so I get an error when I try to do so:
Is there an option I'm missing, or is what I want to do not possible? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Welcome @vritant24! 👋 declare global {
namespace JSX {
// this merges with the existing intrinsic elements, adding 'my-custom-tag' and its props
interface IntrinsicElements {
'my-custom-tag': {'my-custom-attribute': string}
}
}
} source: related discussion over in |
Beta Was this translation helpful? Give feedback.
Welcome @vritant24! 👋
The React/JSX types allow adding additional elements to
JSX.IntrinsicElements
This can look like:
source: related discussion over in
react-markdown
which uses similar typings remarkjs/react-markdown#622 (comment)