I have a function that returns data. The object that gets returned contains headerMenu, page, content and footer. These are all returned as objects of which all of this is defined in DataProps
With the line
const { headerMenu, page: { content }, footer }: DataProps = data
Its throwing an error saying that Type '{}' is missing the following properties from type 'DataProps': headerMenu, page, content, footer
But we can see the props are defined here? What am I missing here or can we not use destructuring in TS
Full component code below
type IndexProps = {
postData: object,
preview: boolean,
}
type PreviewSubscriptionProps = {
data: object,
}
type DataProps = {
headerMenu: object,
page: object,
content: object,
footer: object,
}
export default function Index({ postData, preview } : IndexProps) {
const router = useRouter();
const {data} : PreviewSubscriptionProps = usePreviewSubscription(HomepageGroq, {
initialData: postData,
enabled: preview || router.query.preview !== undefined,
});
const { headerMenu, page: { content }, footer }: DataProps = data
return (
<>
<SiteHeader headerMenu={headerMenu} />
<Content content={content} />
<SiteFooter footer={footer} />
</>
);
}```