(code at the end)
While attempting to write section.full.link
, I encountered the following error:
Property 'link' does not exist on type 'SectionSingle | SectionTitle | SectionHeaderMedia'. Property 'link' does not exist on type 'SectionSingle'.ts(2339)
I'm struggling to figure out how to resolve this error. Adding a ?
after the full
property or something similar did not help.
Here is the code snippet:
export type Section = {
type: "single" | "double" | "title" | "headerMedia";
full?: SectionSingle | SectionTitle | SectionHeaderMedia;
}
export type SectionSingle = {
type: "text" | "media";
content: any;
}
export type SectionTitle = {
title: string;
}
export type SectionHeaderMedia = {
link: string;
alt: string;
}
var section: Section = {
type: "headerMedia",
full: {
link: "/somelink",
alt: "some alt text"
}
}
const cond = section.type === "headerMedia" ? `${section.full.link}` : null
console.log(cond)