From 1411fb96dc33e011e270e1f2c1092332aa844fb3 Mon Sep 17 00:00:00 2001 From: Simon Brunel Date: Sat, 15 Dec 2018 12:37:49 +0100 Subject: [PATCH] Allow module augmentation for chart.js plugin options --- types/chart.js/chart.js-tests.ts | 6 +++++- types/chart.js/index.d.ts | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/types/chart.js/chart.js-tests.ts b/types/chart.js/chart.js-tests.ts index fd5ed53e80..e35c556b56 100644 --- a/types/chart.js/chart.js-tests.ts +++ b/types/chart.js/chart.js-tests.ts @@ -71,7 +71,11 @@ const chart: Chart = new Chart(ctx, { padding: 40 } }, - devicePixelRatio: 2 + devicePixelRatio: 2, + plugins: { + bar: false, + foo: {} + } } }); chart.update(); diff --git a/types/chart.js/index.d.ts b/types/chart.js/index.d.ts index 2803def896..ca28a1a9f6 100644 --- a/types/chart.js/index.d.ts +++ b/types/chart.js/index.d.ts @@ -284,8 +284,7 @@ declare namespace Chart { circumference?: number; rotation?: number; devicePixelRatio?: number; - // Plugins can require any options - plugins?: { [pluginId: string]: any }; + plugins?: ChartPluginsOptions; } interface ChartFontOptions { @@ -367,6 +366,12 @@ declare namespace Chart { borderWidth?: number; } + // NOTE: declare plugin options as interface instead of inline '{ [plugin: string]: any }' + // to allow module augmentation in case some plugins want to strictly type their options. + interface ChartPluginsOptions { + [pluginId: string]: any; + } + interface ChartTooltipsStaticConfiguration { positioners: { [mode: string]: ChartTooltipPositioner }; }