amcharts5
amcharts5 copied to clipboard
How to assign type for setAll() method?
I am drawing a map chart to set markers at certain coordinates. However, my typescript warns me for putting my data type into unknown[]
.
const visitedRestaurantPointSeries = chart.series.push(
am5map.MapPointSeries.new(root, {
latitudeField: "latitude",
longitudeField: "longitude",
})
);
visitedRestaurantPointSeries.data.setAll(visitedRestaurants); <--- this here.
If I put exclamation mark at visitedRestaurants!
like this, it stops. However, I don't think this is the best solution.
I have read the docs and it doesn't seem to have a guide for this.
I'm using amcharts5, nextjs 12.2. Thanks.
Environment (if applicable)
Additional context
Well, setAll()
method does not accept undefined
.
So if the !
workaround is not good enough, you can do a check like this:
visitedRestaurantPointSeries.data.setAll(visitedRestaurants || []);
Hmm I was expecting using generic to somehow fix the allowed type for setAll()
method. Are there any?
setAll()
needs an Array
. Not entirely sure how generics could help you work around it to allow passing in anything else.
This issue is stale because it has been open 30 days with no activity. It will be closed in 5 days unless a new comment is added.