I am using typescript to write redux application.
var item = React.createClass({ render: function() { return (<div>hello world</div>) } }); export default class ItemList extends Component<any, any> { render() { return (<item />) } }
Then typescript complains this:
Property 'item' does not exist on type 'JSX.IntrinsicElements'.
The error "Property does not exist on type 'JSX. IntrinsicElements'" occurs when a component's name starts with a lowercase letter. To solve the error, make sure to always start component names with a capital letter, install the types for React and restart your dev server.
Type Checking For React, intrinsic elements are emitted as strings ( React. createElement("div") ), whereas a component you've created is not ( React. createElement(MyComponent) ). The types of the attributes being passed in the JSX element should be looked up differently.
Your component must start with a capital letter I
instead of small letter i
otherwise TypeScript would yell. Changing item
to Item
should fix it:
var Item = React.createClass({ render: function() { return (<div>hello world</div>) } }); export default class ItemList extends Component<any, any> { render() { return (<Item />) } }
You can declare your custom element type like this:
import * as React from 'react' declare global { namespace JSX { interface IntrinsicElements { item: React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>; } } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With