diff --git a/docs/developers/plugins.md b/docs/developers/plugins.md index 60747416b91..4468a58f52e 100644 --- a/docs/developers/plugins.md +++ b/docs/developers/plugins.md @@ -197,7 +197,7 @@ declare module 'chart.js' { interface PluginOptionsByType { customCanvasBackgroundColor?: { color?: string - } + } | false } } ``` diff --git a/src/types/index.d.ts b/src/types/index.d.ts index 83ad302e30a..65e1213dcd7 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -2913,13 +2913,13 @@ export interface TooltipItem { } export interface PluginOptionsByType { - colors: ColorsPluginOptions; - decimation: DecimationOptions; - filler: FillerOptions; - legend: LegendOptions; - subtitle: TitleOptions; - title: TitleOptions; - tooltip: TooltipOptions; + colors: ColorsPluginOptions | false; + decimation: DecimationOptions | false; + filler: FillerOptions | false; + legend: LegendOptions | false; + subtitle: TitleOptions | false; + title: TitleOptions | false; + tooltip: TooltipOptions | false; } export interface PluginChartOptions { plugins: PluginOptionsByType; diff --git a/test/types/defaults.ts b/test/types/defaults.ts index 84071849245..d20415df1ca 100644 --- a/test/types/defaults.ts +++ b/test/types/defaults.ts @@ -1,8 +1,8 @@ -import { Chart } from '../../src/types.js'; +import { Chart, TitleOptions, TooltipOptions } from '../../src/types.js'; Chart.defaults.scales.time.time.minUnit = 'day'; -Chart.defaults.plugins.title.display = false; +(Chart.defaults.plugins.title as TitleOptions).display = false; Chart.defaults.datasets.bar.backgroundColor = 'red'; @@ -27,4 +27,4 @@ Chart.defaults.layout = { }, }; -Chart.defaults.plugins.tooltip.boxPadding = 3; +(Chart.defaults.plugins.tooltip as TooltipOptions).boxPadding = 3; diff --git a/test/types/overrides.ts b/test/types/overrides.ts index b4da296a322..9085dd98356 100644 --- a/test/types/overrides.ts +++ b/test/types/overrides.ts @@ -1,8 +1,8 @@ -import { Chart } from '../../src/types.js'; +import { Chart, TitleOptions } from '../../src/types.js'; Chart.overrides.bar.scales.x.type = 'time'; -Chart.overrides.bar.plugins.title.display = false; +(Chart.overrides.bar.plugins.title as TitleOptions).display = false; Chart.overrides.line.datasets.bar.backgroundColor = 'red'; diff --git a/test/types/plugins/defaults.ts b/test/types/plugins/defaults.ts index 55a08ac7ad8..a11c4dce09a 100644 --- a/test/types/plugins/defaults.ts +++ b/test/types/plugins/defaults.ts @@ -1,8 +1,9 @@ -import { defaults } from '../../../src/types.js'; +import { defaults, LegendOptions } from '../../../src/types.js'; // https://github.com/chartjs/Chart.js/issues/8711 -const original = defaults.plugins.legend.labels.generateLabels; +const original = (defaults.plugins.legend as LegendOptions<"line">).labels.generateLabels; +// @ts-ignore defaults.plugins.legend.labels.generateLabels = function(chart) { return [{ datasetIndex: 0, diff --git a/test/types/plugins/disable.ts b/test/types/plugins/disable.ts new file mode 100644 index 00000000000..d6ed066e192 --- /dev/null +++ b/test/types/plugins/disable.ts @@ -0,0 +1,16 @@ +import { Chart } from '../../../src/types.js'; + +const chart = new Chart('id', { + type: 'bubble', + data: { + labels: [], + datasets: [{ + data: [] + }] + }, + options: { + plugins: { + legend: false + } + } +}); \ No newline at end of file diff --git a/test/types/plugins/plugin.tooltip/tooltip_parsed_data_chart_defaults.ts b/test/types/plugins/plugin.tooltip/tooltip_parsed_data_chart_defaults.ts index 5072824bcf9..b5584adeb43 100644 --- a/test/types/plugins/plugin.tooltip/tooltip_parsed_data_chart_defaults.ts +++ b/test/types/plugins/plugin.tooltip/tooltip_parsed_data_chart_defaults.ts @@ -1,6 +1,6 @@ -import { Chart } from '../../../../src/types.js'; +import { Chart, TooltipOptions } from '../../../../src/types.js'; -Chart.overrides.bubble.plugins.tooltip.callbacks.label = (item) => { +(Chart.overrides.bubble.plugins.tooltip as TooltipOptions<'bubble'>).callbacks.label = (item) => { const { x, y, _custom: r } = item.parsed; return `${item.label}: (${x}, ${y}, ${r})`; };