chartjs / chartjs/chartjs-plugin-annotation

Invalid typing probably?

Open
#901 3 comments 0 reactions 0 assignees View on GitHub
enhancement types
Dominant language
JavaScript
Stars
623
Forks
377
PR merge metrics
No merged PRs in 30d

Description

Hello again!

I saw lot's of usage of `EventContext.element` here and there in examples and tests.
e.g. [here](https://github.com/chartjs/chartjs-plugin-annotation/blob/ebd5c6f9c2f56dcf1cf213aa7af2a9e93d38059f/test/fixtures/ellipse/label-dynamic.js#L34C1-L35C1:
```javascript
element.label.options.display = true;
```

But in typings I see that `label` is marked as `AnnotationElement` [here](https://github.com/chartjs/chartjs-plugin-annotation/blob/ebd5c6f9c2f56dcf1cf213aa7af2a9e93d38059f/types/element.d.ts#L16).
Idk, did I understand it correctly, but I believe it should be [CoreLabelOptions](https://github.com/chartjs/chartjs-plugin-annotation/blob/ebd5c6f9c2f56dcf1cf213aa7af2a9e93d38059f/types/label.d.ts#L40) or smth similar?

I believe typing checker or eslint passes successfully because lot's of properties have the same name. But if you try to replace the code in the example above to:

```javascript
element.label.options.content= "new label text";
```

you'll see an error since `element.label.options` is not type of `AnnotationOptions`

But maybe that's just things are mixed up in my head a bit 🙂

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.