From 9432030b65661bac26dccbaf354542e9c2d1b5d8 Mon Sep 17 00:00:00 2001 From: stockiNail Date: Thu, 13 Jul 2023 09:59:01 +0200 Subject: [PATCH] Add missing feature for disabling plugins in TyeScript --- docs/developers/plugins.md | 9 ++++++++- src/types/index.d.ts | 23 +++++++++++++++++++---- test/types/plugins/disable.ts | 29 +++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 test/types/plugins/disable.ts diff --git a/docs/developers/plugins.md b/docs/developers/plugins.md index 60747416b91..7227964502a 100644 --- a/docs/developers/plugins.md +++ b/docs/developers/plugins.md @@ -194,10 +194,17 @@ For example, to provide typings for the [`canvas backgroundColor plugin`](../con import {ChartType, Plugin} from 'chart.js'; declare module 'chart.js' { - interface PluginOptionsByType { + // For defaults options + interface DefaultsPluginOptionsByType { customCanvasBackgroundColor?: { color?: string } } + // for chart options + interface PluginOptionsByType { + customCanvasBackgroundColor?: { + color?: string + } | false + } } ``` diff --git a/src/types/index.d.ts b/src/types/index.d.ts index 83ad302e30a..7c28892a399 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -663,7 +663,7 @@ export interface DatasetControllerChartComponent extends ChartComponent { }; } -export interface Defaults extends CoreChartOptions, ElementChartOptions, PluginChartOptions { +export interface Defaults extends CoreChartOptions, ElementChartOptions, DefaultsPluginChartOptions { scale: ScaleOptionsByType; scales: { @@ -701,7 +701,7 @@ export type Overrides = { [key in ChartType]: CoreChartOptions & ElementChartOptions & - PluginChartOptions & + DefaultsPluginChartOptions & DatasetChartOptions & ScaleChartOptions & ChartTypeRegistry[key]['chartOptions']; @@ -2912,7 +2912,7 @@ export interface TooltipItem { element: Element; } -export interface PluginOptionsByType { +export interface DefaultsPluginOptionsByType { colors: ColorsPluginOptions; decimation: DecimationOptions; filler: FillerOptions; @@ -2921,8 +2921,23 @@ export interface PluginOptionsByType { title: TitleOptions; tooltip: TooltipOptions; } + +export interface PluginOptionsByType { + colors: ColorsPluginOptions | false; + decimation: DecimationOptions | false; + filler: FillerOptions | false; + legend: LegendOptions | false; + subtitle: TitleOptions | false; + title: TitleOptions | false; + tooltip: TooltipOptions | false; +} + +export interface DefaultsPluginChartOptions { + plugins: DefaultsPluginOptionsByType; +} + export interface PluginChartOptions { - plugins: PluginOptionsByType; + plugins: PluginOptionsByType | false; } export interface BorderOptions { diff --git a/test/types/plugins/disable.ts b/test/types/plugins/disable.ts new file mode 100644 index 00000000000..a1281674329 --- /dev/null +++ b/test/types/plugins/disable.ts @@ -0,0 +1,29 @@ +import { Chart } from '../../../src/types.js'; + +const chart = new Chart('id', { + type: 'bubble', + data: { + labels: [], + datasets: [{ + data: [] + }] + }, + options: { + plugins: false + } +}); + +const chart1 = new Chart('id', { + type: 'bubble', + data: { + labels: [], + datasets: [{ + data: [] + }] + }, + options: { + plugins: { + legend: false + } + } +}); \ No newline at end of file