$context not on type Element when accessing activeElements from click event
- Dominant language
- JavaScript
- Stars
- 67.7k
- Forks
- 11.9k
- Avg merge
- 7h 39m
- Merged PRs (30d)
- 5
Description
### 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_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.