Home > database >  Property does not exist on type ''
Property does not exist on type ''

Time:06-09

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?

CodePudding user response:

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

  • Related