The error "Type '{ children: Element; }' has no properties in common with type 'IntrinsicAttributes'." occurs when we pass in children to a component which doesn't take any props.
Problem
The above error occurred as the result of the following code:
Here, we are passing the children prop to the "Container" component, which doesn't have the children prop defined.
When a component is used with an opening and closing tag, everything written in between these tags are considered to be the "children" props.
Solution
You can solve the error by defining the children as a prop to the "Container" component and since we are using TypeScript, we need to type the "Container" component of its prop inputs. See the solved code for the above error:
Here, we have defined the props and assigned the type of the props for TypeScript. Then we accessed the passed on children as "props.children".
Another way to ignore or disable the error is to use the "any" type on the props. This will effectively disable the type checking of TypeScript.
This is not a good practice since the whole reason for using TypeScript is to recognise and handle these errors.
Alternatively, if you passed in the children prop by mistake, you need to remove the child and use a self-closing tag while calling the component.
Self closing tags have the format of <Component/>. They do not have a opening and closing tag and doesn't have any child elements in between.
Conclusion
If you are passing any children to a component, make sure the component has props defined to take in the children. While using TypeScript, it is necessary to define the typing of the props being passed. Otherwise, errors such as mentioned above would occur.
Here is another example of an error that was caused by not typing the children prop.
Thank you for reading, Check out my other articles. See you in the next one.