From 92771df1588e80df1d5a70cbd8d53557222c3205 Mon Sep 17 00:00:00 2001 From: Simon Brunel Date: Sun, 5 May 2019 09:37:34 +0200 Subject: [PATCH] Fix TS default export of the plugin instance --- types/index.d.ts | 8 ++++++-- types/test/exports.ts | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 types/test/exports.ts diff --git a/types/index.d.ts b/types/index.d.ts index 2c95864..ec0e831 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,7 +1,5 @@ import { Options } from './options'; -export * from './context'; - declare module 'chart.js' { interface ChartDataSets { /** @@ -19,3 +17,9 @@ declare module 'chart.js' { datalabels?: Options } } + +declare const plugin: object; + +export * from './context'; + +export default plugin; diff --git a/types/test/exports.ts b/types/test/exports.ts new file mode 100644 index 0000000..994b13d --- /dev/null +++ b/types/test/exports.ts @@ -0,0 +1,21 @@ +// https://github.com/chartjs/chartjs-plugin-datalabels/issues/130 +import { Chart } from 'chart.js' +import { Context } from '../index' +import Plugin from '../index' + +// Plugin instance +Chart.plugins.register(Plugin) +Chart.plugins.unregister(Plugin) + +const chart = new Chart('id', { + plugins: [Plugin] +}) + +// Scriptable context +const ctx: Context = { + active: true, + chart: chart, + datasetIndex: 0, + dataIndex: 0, + dataset: {} +}