Why push shows argument of type 'any[]' is not assignable to parameter of type 'never' error?

Parsaria picture Parsaria · Aug 28, 2018 · Viewed 32.8k times · Source

In this code i get the fallowing error:

Argument of type 'any[]' is not assignable to parameter of type 'never'

var markers: [];
this.Getlapoints(this.map.getCenter(), 500000).then(data => {
  for (var key in data) {
    Leaflet.marker(data[key].location, //{ icon: greenIcon            }
    ).addTo(this.map).bindPopup(data[key].caption);
    // markers.push(data[key].location.lat,data[key].location.lng);
    // markers.push(data[key].location);

    var lat = data[key].location.lat;
    var lng = data[key].location.lng;
    markers.push([lat, lng]);
  }
  console.log(markers);
});

Answer

Matt McCutchen picture Matt McCutchen · Aug 28, 2018

With var markers: [] you are declaring the markers array as having the type of a permanently empty array. You probably meant var markers = [] to initialize it to empty but allow items to be added.