For the death of me I cannot figure this out for the past three hours and I am very frustrated so I apologize in advance if I sound a big aggressive.
All I want is to be able to define a typescript interface for my component and have it extend the default interface any component uses, to avoid having to declare every goddamn default prop such as className, onClick and the like in my own interface.
I have this component:
import React, { useEffect, useRef, FunctionComponent } from 'react'
import './style.scss'
interface ISideProps {
wideModeEnabled: boolean
toggleWideMode
setFocus
}
const AppLayoutSide: FunctionComponent<ISideProps> = (props) => {
const ref = useRef() as any
...
...
etc.
return <div {...props} />
}
Now there is no error in this component, at least typescript doesn't give any. But if I try to render this component in another one, for example like this:
const otherComponent = () => {
return (
<div className='content'>
<Menu />
<Main />
<Side
className={'whatever'} //Typescript error happens here
wideModeEnabled={wideMode}
toggleWideMode={toggleWideMode}
setFocus={setSideFocus}
/>
</div>
)
}
And the error says:
Type '{ className: string; wideModeEnabled: boolean; toggleWideMode: () => void; setFocus: Dispatch<SetStateAction>; }' is not assignable to type 'IntrinsicAttributes & ISideProps & { children?: ReactNode; }'.
Property 'className' does not exist on type 'IntrinsicAttributes & ISideProps & { children?: ReactNode; }'.ts(2322)
Which is obviously true, I've not defined className on ISideProps interface, but I want to extend the default react props goddamn it! And no matter what I've tried I cannot seem to get it to work. Every guide online keeps suggesting to add : FunctionalComponent<ISideProps> to the component declaration, and I did, but it doesn't solve a thing.
Help please, I am losing my mind.