amcharts5 icon indicating copy to clipboard operation
amcharts5 copied to clipboard

How to assign type for setAll() method?

Open intaek-h opened this issue 2 years ago • 3 comments

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.

스크린샷 2022-09-15 오후 8 38 51

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

intaek-h avatar Sep 15 '22 11:09 intaek-h

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 || []);

martynasma avatar Sep 16 '22 05:09 martynasma

Hmm I was expecting using generic to somehow fix the allowed type for setAll() method. Are there any?

intaek-h avatar Sep 16 '22 06:09 intaek-h

setAll() needs an Array. Not entirely sure how generics could help you work around it to allow passing in anything else.

martynasma avatar Sep 16 '22 06:09 martynasma

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.

github-actions[bot] avatar Oct 17 '22 00:10 github-actions[bot]