Chartjs-Custom registered Chart.js Plugin is not assignable to type '_DeepPartialObject<PluginOptionsByType<keyof ChartTypeRegistry>>'

1👍

Ok, found it…

I forgot to read this part: https://www.chartjs.org/docs/latest/developers/plugins.html#typescript-typings

If you want your plugin to be statically typed, you must provide a .d.ts TypeScript declaration file. Chart.js provides a way to augment built-in types with user-defined ones, by using the concept of "declaration merging".
When adding a plugin, PluginOptionsByType must contain the declarations for the plugin.

Added the d.ts file:

import {ChartType, Plugin} from 'chart.js';

declare module 'chart.js' {
  interface PluginOptionsByType<TType extends ChartType = ChartType> {
    tstPlugin?: {
      color?: string
    }
  }
}

And problem solved… I was about to delete the post but I leave it because maybe it will be useful to someone else who is doing their first steps with this like me

Leave a comment