I am migrating my React files to .tsx and have come across this issue.
Footer.tsx
const Footer = ({ children, inModal }) => (
    <footer className={'(inModal ? " in-modal" : "") }>
        <div>
            {children}
        </div>
    </footer>
);
export default Footer;
ParentComponent.tsx
import Footer from 'path/to/Footer';
export class ParentComponent extends React.Component<{ showSomething: (() => void) }> {
    render() {
        return (
            <Footer>
                <Button onClick={() => this.props.showSomething()}>Add</Button>
            </Footer>
        );
    }
}
There is a red underline underneath the <Footer> tag with the error:
[ts] Type '{ children: Element; }' is not assignable to type 'IntrinsicAttributes & { children: any; inModal: any; }'. Type '{ children: Element; }' is not assignable to type '{ children: any; inModal: any; }'. Property 'inModal' is missing in type '{ children: Element; }'.
I'm not quite sure how to decipher what that means. Any help would be greatly appreciated.
The error is indicating that the Footer component requires a prop inModal to be passed to it. To fix the issue, you can either:
Give it a default value:
const Footer = ({ children, inModal = false }) => ...
Tell typescript that it's optional:
const Footer = ({ children, inModal }: {children: any, inModal?: boolean}) => ...
Or explicitly provide that prop whenever you use the footer:
<Footer inModal={false}> ... </Footer>
                        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