Hi Fares
Thanks you for your reply.
Sorry, the error message seems to be different due to the simplification.
Below is the code that actually works.
type ProjectProps = {
project: ProjectDocument<string>
}
const Project: NextPage<ProjectProps> = ({ project }) => {
if( !isFilled.contentRelationship(project.data.creator) ) { // Need to validate again, even though it is obvious.
return <></>
}
const creator = project.data.creator
console.log('creator.data.name:', creator.data.name) // This work but show error in VScode
/**
(property) FilledLinkToDocumentField<"creator", string, never>.data?: undefined
Object is possibly 'undefined'.ts(2532)
*/
return (
<></>
)
}
export default Project
export const getStaticProps = async ({ params, previewData }: any /** I don't know what type.🥹 */) => {
const client = createClient({ previewData })
const project = await client.getByUID<ProjectDocument>('project', params.uid, {
fetchLinks: ['creator.name', 'creator.face']
})
if( !isFilled.contentRelationship(project.data.creator) ) {
return {
notFound: true
}
}
return {
props: {
project
},
}
}
I know that creator.data.name is accessible and works, but TypeScript don't know it.