-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to disable global plugins in typescript #11398
Comments
I have done a quick drill-down with the proposed solution but I see some issues. Test definitions: interface TitleOptions {
display: boolean;
}
interface PluginOptionsByType {
title: TitleOptions | false;
}
interface PluginChartOptions {
plugins: PluginOptionsByType | false;
}
interface Defaults extends PluginChartOptions {
}
class Chart {
static readonly defaults: Defaults;
}
Chart.defaults.plugins = false; // works
Chart.defaults.plugins.title = false; // issue: Property 'title' does not exist on type 'false | PluginOptionsByType'.
// Property 'title' does not exist on type 'false'.(2339)
Chart.defaults.plugins.title.display = false; // issue: Property 'title' does not exist on type 'false | PluginOptionsByType'.
// Property 'title' does not exist on type 'false'.(2339) More time is needed to me (due to my lack of knowledge on TS) :( |
It seems a casting is needed... (Chart.defaults.plugins as PluginOptionsByType).title = false;
((Chart.defaults.plugins as PluginOptionsByType).title as TitleOptions).display = false; If so, it could be a breaking change to whoever is accessing to plugin options. |
It does not make sense to set false to defaults because otherwise we could loose the defaults of plugin. |
Because of #11422 which reverted the changes, I would suggest to re-open the issue, in order to avoid to forget it and maybe we could tag it as breaking change. |
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
.The same when you want to disable all plugins, as reported to the doc:
Current behavior
When you use TS, you can not disable the plugins as documented, getting the error:
Reproducible sample
https://github.com/stockiNail/chartjs-11288
Optional extra steps/info to reproduce
index.ts
npm run test
Possible solution
Add to
PluginOptionsByType
interface items the options to be set tofalse
.Example:
Add to
PluginChartOptions
interfaceplugins
items the options to be set tofalse
.Context
No response
chart.js version
v4.3.0
Browser name and version
FF 115.0.1
Link to your project
https://github.com/stockiNail/chartjs-11288
The text was updated successfully, but these errors were encountered: