40

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);
});
Parsaria
  • 1,049
  • 3
  • 12
  • 18

4 Answers4

64

Change this :

const a = [];

By this :

const a = Array();
Denis TRUFFAUT
  • 1,017
  • 10
  • 11
50

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.

Matt McCutchen
  • 28,856
  • 2
  • 68
  • 75
  • 14
    thanks, this is the answer to my problem, but I was only able to surmount it like this: `let all: any[] = []` – JP Lew Apr 24 '19 at 22:52
7

In tsconfig.json -

 "noImplicitReturns": false,

 "strictNullChecks":false,

enter image description here

Solution: type as 'never'

enter image description here

rohit.khurmi095
  • 2,203
  • 1
  • 14
  • 12
1

The never type is a subtype of, and assignable to, every type; however, no type is a subtype of, or assignable to, never (except never itself). Even any isn’t assignable to never.

From the TypeScript docs

Programmer
  • 1,973
  • 1
  • 12
  • 20
  • I don't what are you suppose to do. You can replace the `never` with `null` or empty string or 'never' (as string). – Programmer Aug 28 '18 at 09:47
  • I want to store all posts latlang in array to use in leaflet, LatLngBounds to fit all markers in map view. – Parsaria Aug 28 '18 at 13:02