-
Notifications
You must be signed in to change notification settings - Fork 12k
Closed
Labels
Description
Expected behavior
As reported from the doc, how to disable plugins https://www.chartjs.org/docs/latest/developers/plugins.html#disable-plugins, you can disable the invocation of a plugin registered globally setting in the chart options as false
.
Chart.register({
id: 'p1',
// ...
});
const chart = new Chart(ctx, {
options: {
plugins: {
p1: false // disable plugin 'p1' for this instance
}
}
});
The same when you want to disable all plugins, as reported to the doc:
const chart = new Chart(ctx, {
options: {
plugins: false // all plugins are disabled for this instance
}
});
Current behavior
When you use TS, you can not disable the plugins as documented, getting the error:
index.ts:28:4 - error TS2559: Type 'false' has no properties in common with type '_DeepPartialObject<LegendOptions<"bar">>'.
28 legend: false,
~~~~~~
node_modules/chart.js/dist/types/index.d.ts:2909:3
2909 legend: LegendOptions<TType>;
~~~~~~
The expected type comes from property 'legend' which is declared here on type '_DeepPartialObject<PluginOptionsByType<"bar">>'
Reproducible sample
https://github.com/stockiNail/chartjs-11288
Optional extra steps/info to reproduce
- edit
index.ts
- set
options: {
plugins: {
legend: false,
}
}
- execute
npm run test
Possible solution
Add to PluginOptionsByType
interface items the options to be set to false
.
Example:
export interface PluginOptionsByType<TType extends ChartType> {
colors: ColorsPluginOptions | false;
decimation: DecimationOptions | false;
filler: FillerOptions | false;
legend: LegendOptions<TType> | false;
subtitle: TitleOptions | false;
title: TitleOptions | false;
tooltip: TooltipOptions<TType> | false;
}
Add to PluginChartOptions
interface plugins
items the options to be set to false
.
export interface PluginChartOptions<TType extends ChartType> {
plugins: PluginOptionsByType<TType> | false;
}
Context
No response
chart.js version
v4.3.0
Browser name and version
FF 115.0.1