chartjs / chartjs/Chart.js

htmlLegend is missing in PluginOptionsByType in TypeScript 5.5.3 definitions

Open
#11,877 3 comments 1 reaction 0 assignees View on GitHub
type: types
Dominant language
JavaScript
Stars
67.7k
Forks
11.9k
Avg merge
7h 39m
Merged PRs (30d)
5

Description

### Expected behavior

When declaring a ChartOptions with a declared type, IE:
```
private doughnutOptions: ChartOptions<"doughnut">
```
And initializing the options with a custom html legend,
```
this.doughnutOptions = {
plugins: {
...
htmlLegend: {
containerId: `myContainerId`,
}
}
}
```
There should be no lint errors on eslint.

### Current behavior

When declaring ChartOptions with the above syntax, the following error is observed:
```
Object literal may only specify known properties, and 'htmlLegend' does not exist in type '_DeepPartialObject>'.ts(2353)
```
This error can be cleared by changing the variable for chart options to:
```
private doughnutOptions: ChartOptions
```
However, this fails our lint for [typescript/no-redundant-type-constituents](https://typescript-eslint.io/rules/no-redundant-type-constituents).
For now, we are considering disabling lint for that line, but we would like to know, is there something we're doing wrong that `htmlLegend` is not appearing anywhere in our TypeScript definitions for chart.js? We are on version 4.4.3.

### Reproducible sample

https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgYQBYENZwL5wGZQQhwDkAxhrAHQBWAziQNwCwAUGwG6ZxkwAecALxwAJhDIBXEAFMAdjCoBzaTACiAG2kz5AIQCeASREAKAEQg9aTDFMBKOOjpwAEgBUAsgBlk6WVzoaWnIwLKxcUHAWVljCstIA7iiUMMa8fAA0iGxwOXAwemDSAFykYhKKqLISMCTp2bki6DDoJQj1ubnq6ABG0up0JQDapgBK0iKmmaY66hLSk3CmAJp96hDxC6YA4lDScpsAChJQYJqbAPJQvsqmALp1rB0djc10KgNwg22PT79dveoSiQAMRwCB4OAANQgMGkDAev1+LxanwAjAAmTKogCcmQAzJkAKyZTFwPH3dpPbC3SnYBG5CBgGDACCyD7fX6ncrANmtSkdTTKWQiPk-RGiYB0U7oPQlPDofrSem-On83KoGAgdSeaRCkVZMWIsis5o86RQIwlUyCuQiIyTNU5VWGp3K3J0MgKuGi8V8H3iuCOnBujqyg0BwMu3LYNUxw1x7C2RhAA

### Optional extra steps/info to reproduce

_No response_

### Possible solution

_No response_

### Context

We are using a custom html legend for our doughnut charts

### chart.js version

v4.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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.