-
The error happens when running interface ArticleProps {
title: any
children?: any
heading?: "h1" | "h2" | "h3"
}
function Article(props: ArticleProps) {
const Heading = props.heading as keyof JSX.IntrinsicElements
return (
<Heading>{props.title}</Heading>
{props.children}
</div>
)
} The error says there is missing argument Without this library, this code is compiled with no error. Edit: |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 13 replies
-
What are you passing as |
Beta Was this translation helpful? Give feedback.
-
let's discuss it here for the moment - i know too little about TS but JSX.IntrinsicElements does not contain dom elements, it contains any natire (lowercase) element (div, span, mesh, meshBasicMaterial, ...), maybe that's the issue. primitiveprops only applies to a single native element "primitive" which is executed like this: imo Heading should be a string, or a key of a known list or permissible strings. making it a key of any IntrinsicElement kind of means it will have to adhere to any arbitrary rule that any element exposes. |
Beta Was this translation helpful? Give feedback.
-
It doesn't seem pretty but it works when changing const Heading = props.heading as keyof JSX.IntrinsicElements to const Heading = props.heading as unknown as (props: React.HTMLAttributes<HTMLHeadingElement>) => JSX.Element Although, It might be changed to const Heading = props.heading as any |
Beta Was this translation helpful? Give feedback.
It doesn't seem pretty but it works when changing
to
Although, It might be changed to