Skip to content

EventEmitter type is object, should be ActiveElement #1975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
florestankorp opened this issue Jun 16, 2024 · 1 comment
Open

EventEmitter type is object, should be ActiveElement #1975

florestankorp opened this issue Jun 16, 2024 · 1 comment

Comments

@florestankorp
Copy link

Reproduction of the problem

<canvas (chartClick)="chartClicked($event)"> </canvas>
public chartClicked(event: { event?: ChartEvent; active?: object[] }): void {
  if (event.active && event.active.length > 0) {
    const myChartDataLabelIndex = event.active[0].index; // `Property 'index' does not exist on type 'object'.ts(2339)`
    console.log(myChartDataLabelIndex);
  }
}

Suggested fix:

libs/ng2-charts/src/lib/base-chart.directive.ts

  @Output() public chartClick: EventEmitter<{
    event?: ChartEvent;
    active?: ActiveElement[];
  }> = new EventEmitter();

  @Output() public chartHover: EventEmitter<{
    event: ChartEvent;
    active: ActiveElement[];
  }> = new EventEmitter();
@Matthiasvanderhallen
Copy link

Matthiasvanderhallen commented Mar 24, 2025

We would love to see this fixed, I looked around in the codebase and found no reason for active to be typed as the less restrictive object[]... Nor for the possibility of leaving those undefined either.

To be honest, even better would be a

type ChartMouseEvent = { event:ChartEvent, active: ActiveElement[] }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants