Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Property does not exist on type ''

I am getting data from an api and i have written it’s types like this

interface Daily {
  dt: number;
  sunrise: number;
  sunset: number;
  moonrise: number;
  moonset: number;
  moon_phase: number;
  temp: {day: number, eve: number, max: number, min: number, morn: number, night: number}[];
  feels_like: {day: number, night: number, eve: number, morn: number}[];
  pressure: number;
  humidity: number;
  dew_point: number;
  wind_speed: number;
  wind_deg: number;
  wind_gust: number;
  weather:  { id: number, main: string, description: string, icon:string }[];
  clouds: number;
  pop: number;
  uvi: number;
}

interface PropsType{
  weather:{
    lat: number;
    lon: number;
    timezone: string;
    timezone_offset: number;
    daily: Daily[];
  }
}

Now when I try to access props.weather.daily.weather[0] it give me the error "Property weather’ does not exist on type ‘Daily[]’." I don’t understand why? How do i fix this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

daily is an array so you can’t access daily.weather
Maybe you meant to daily[0].weather

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading