chartjs / Chart.js

Simple HTML5 Charts using the <canvas> tag
https://www.chartjs.org/
MIT License
64.05k stars 11.88k forks source link

Types of custom plugin options #8051

Closed kryshac closed 3 years ago

kryshac commented 3 years ago

I created a plugin for version 3, but I have problems with the types of options for the plugin

export const FilterGradientResponsive: Plugin<{ color?: string[]; height?: number }> = {
  id: 'filterGradientResponsive',
  ...
}
options: {
  plugins: {
    filterGradientResponsive: {
      color: ['rgba(253.83, 163.40, 0.17, 0.85)', 'rgba(222.84, 0.29, 161.09, 0.78)'],
    },
  },
}

Error: index.d.ts(1516, 3): The expected type comes from property 'options' which is declared here on type 'ChartConfiguration<"line", number[], string>'

kurkle commented 3 years ago

Faced same issue, should be fixed by #8048

Here's how I declared the options in the plugin (needs that PR merged):

declare module 'chart.js' {
  interface PluginOptions {
    annotation: AnnotationPluginOptions;
  }
}
kryshac commented 3 years ago

starting with version v3.0.0-beta.10 needs to change in this: PluginOptions -> PluginOptionsByType

declare module 'chart.js' {
  interface PluginOptionsByType {
    annotation: AnnotationPluginOptions;
  }
}