I have a react
next.js
application. where I am trying to pass data using interface props into another component. while running build I am encountering an issue. below are the details.
I have a interface ModelProps
export interface ModelProps {
modalOpen?: boolean;
data: any;
reloadParent: () => void;
closeModal: () => void;
}
this is my parent component
function page(props: ModelProps) {
const { modalOpen, data, reloadParent,closeModal } = props;
return (
<div>
<BookingModalPopup modalOpen={modalOpen} data={data} reloadParent={reloadParent} closeModal={closeModal} />
</div>
)
}
and this is my child component where I am trying to open a popup modal to show some details
interface RequestData {
[key: string]: string;
}
function BookingModalPopup(modelProps: ModelProps) {
const [currentDate, setCurrentDate] = useState(new Date().toISOString().split('T')[0]);
const [msg, setMsg] = useState('');
const [isMsgModalOpen, setIsMsgModalOpen] = useState<boolean>(false);
const [isloaderOpen, setIsLoaderOpen] = useState<boolean>(false);
const [requestData, setRequestData] = useState<RequestData>({});
return (
<div>
<>
<ModelPopup isOpen={isMsgModalOpen} closeModal={closeMsgModal} msg={msg} />
<Loader isOpen={isloaderOpen} />
<My Elements Here>
</>
</div>
)
}
export default BookingModalPopup
whenever i am running npm run build
it is giving below error
Type error: Type 'OmitWithTag<ModelProps, keyof PageProps, "default">' does not satisfy the constraint '{ [x: string]: never; }'.
Property 'modalOpen' is incompatible with index signature.
Type 'boolean' is not assignable to type 'never'.
any help would be appriciated
TIA
2
Answers
You just use the ModelProps interface in your BookingModalPopup component, you can specify the type of the modelProps parameter in the function signature.
The issue is with the code structure. looks like
BookingModalPopup
is a component which is being called from page.tsx which also gets called from another component.remove the page.tsx and directly call
BookingModalPopup
from another componentfor example
and call this
CompA
from another component for examplethis will solve your issue.