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); });
ts(2322) arr[0] = 'a'; We declared an empty array and it got assigned a type of never[] . This type represents an array that will never contain any elements (will always be empty). To solve this, we have to explicitly type the empty array.
The error "Argument of type string | undefined is not assignable to parameter of type string" occurs when a possibly undefined value is passed to a function that expects a string . To solve the error, use a type guard to verify the value is a string before passing it to the function.
The error "Type is not assignable to type 'never'" occurs when we declare an empty state array with the useState hook but don't type the array. To solve the error, use a generic to type the state array, e.g. const [arr, setArr] = useState<string[]>([]) . Here is an example of how the error occurs.
TypeScript introduced a new type never , which indicates the values that will never occur. The never type is used when you are sure that something is never going to occur. For example, you write a function which will not return to its end point or always throws an exception. Example: never.
Change this :
const a = [];
By this :
const a = Array();
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With