Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
Why this next.js and typescript page says "Property 'data' does not exist on type"

I am starting to use typescript with next.js

const Index: NextPage = (props) => {

  return (<p>{prop.data.name}</p>);

}
export default Index;

export const getServerSideProps = async () => {
    const data = await fetch(
        `${server}/api`
    ).then((response) => response.json());
    return {
        props: {data}
    };
};

my editor highlight the word data in {props.data.name} with this message

Property 'data' does not exist on type '{ children?: ReactNode; }'.

how can I define a type from this?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to define a type and pass it to the generic param of NextPage like below

type PictureType = {
   category: string,
   createdAt: string,
   favourites: number,
   isHidden: boolean,
   title: string,
   updatedAt: string,
   url: string,
   user: string,
}
type ResponseDataType = {
   lastPictures: PictureType[],
   picturesByCat: PictureType[]
}
type PageProps = {
   data: ResponseDataType, 
}
const Index: NextPage<PageProps> = (props) => {

  return (<p>{prop.data.name}</p>);

}
export default Index;

export const getServerSideProps = async () => {
    const data = await fetch(
        `${server}/api`
    ).then((response) => response.json());
    return {
        props: {data}
    };
};
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!