Skip to content
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

$context not on type Element when accessing activeElements from click event #11857

Open
dezmon-fernandez opened this issue Aug 7, 2024 · 0 comments
Labels
type: types Typescript type changes

Comments

@dezmon-fernandez
Copy link

Expected behavior

I expect to not have to type cast and do dynamic check to access a property that is there.

Current behavior

    onClick: (event, activeChartElements, chart) => {

      if (isEmpty(activeChartElements)) {
        return;
      }
      const { element } = activeChartElements[0];

      if ('$context' in element && typeof element.$context === 'object') {
        const context = element.$context as { raw: { x: string; y: number } };
        if ('raw' in context) {
          const rawDataPoint = context.raw;
        }
      }

Reproducible sample

https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgYQBYENZwL5wGZQQhwDkAxhrAHQBWAziQNwCwAUGwG6ZxkwAecALxwAJhDIBXEAFMAdjCoBzaTACiAG2kz5AIQCeASREAKAEQg9aTDFMBKOOjpwAEgBUAsgBlk6WVzoaWnIwLKxcUHAWVljCstIA7iiUMMa8fAA0iGxwOXAwemDSAFyk6sBxJOnZuSLoMOglCNW5ueroAEbS6nQlANqmAErSIqaZpjrqEtKjcKYAml3qEPEzpgDiUNJyqwAKElBgmqsA8lC+yqYAulWsLS219XQqPXC9Tbd3n22d6iUkAMRwCB4OAANQgMGkDBun0+DwarwAjAAmTKIgCcmQAzJkAKyZVFwLHXZp3bCXUnYGG5CBgGDACCyF7vT50MjoTTM0ktPiNbl3fk5KmCuB6PkfWFwEXYfnCiVA2TIMpkADWJWM0g4wUy6F4wC10TUmm0MDomQo1nsggAfFl2PKcmRGXR4EgukF5DghA49QbkoETXRegAGS6hT4AegjeVQwCc0j4cfgjLg7W4FqwZGVKqlDp4zvgZ0SwndJqoABInfIEwoi+HcjLWNhbIwgA

Optional extra steps/info to reproduce

No response

Possible solution

Add $context to Element type.

Context

No response

chart.js version

4.4.3

Browser name and version

No response

Link to your project

No response

@LeeLenaleee LeeLenaleee added type: types Typescript type changes and removed type: bug labels Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: types Typescript type changes
Projects
None yet
Development

No branches or pull requests

2 participants