return <my-custom-element />;
Results in error: Property 'my-custom-element' does not exist on type 'JSX.IntrinsicElements'
. As far as I'm aware, this ought to be valid JSX and so compile to:
React.createElement("my-custom-element").
I can get around this by using the second form, but it'd be nice to avoid the check for standard elements (unless it's there for a good reason?)
declare module JSX {
interface IntrinsicElements {
"my-custom-element": MyCustomElementClass
}
}
You can do this to remove the type error, if you'd like.
@weswigham what if the element doesn't have a class?
Try typing it as any
?
Isn't any
a bad pattern?
If you have no type which describes the attributes allowed on the object, any
may be acceptable, in order to allow any attribute to be applied. Alternatively, write an interface for the component.
See this, typescript complains if React component does not start with a capital letter.
I confirm that changing my react components name first letter to uppercase did fix the problem on typescript version 2.3.2
@jyotendra thanks for that starting the component with capital letter fixed the error for me too.
Conclusion:
-> This error is misleading and should spell it out what the actual issue is or...
-> Why on earth is typescript dictating for components to start with uppercase?
It's part of jsx - lowercased names are considered intrinsics, while uppercased names are custom components. They get called differently, too. Intrinsics are just a string passed into createElement, while custom components pass in their constructor.
Most helpful comment
See this, typescript complains if React component does not start with a capital letter.