-
Notifications
You must be signed in to change notification settings - Fork 12k
Closed
Labels
Description
Expected behavior
export interface Plugin<TType extends ChartType = ChartType, O = AnyObject> extends ExtendedPlugin<TType, O> {
afterInit?(chart: Chart<TType>, args: EmptyObject, options: O): void;
// ...and so on
}I'm wondering why the generic argument TType is not provided to all of the hooks for the Chart interface. It will narrow the type and help write more specific plugins for different types of charts.
Current behavior
export interface Plugin<TType extends ChartType = ChartType, O = AnyObject> extends ExtendedPlugin<TType, O> {
afterInit?(chart: Chart, args: EmptyObject, options: O): void;
}Reproducible sample
Possible solution
I'm not sure why the generic argument TType it's not passed down to the Chart class, because the Plugin interface already takes the TType generic argument, so it would be easy to add it to all of the hooks chart argument.
export interface Plugin<TType extends ChartType = ChartType, O = AnyObject> extends ExtendedPlugin<TType, O> {
beforeInit?(chart: Chart<TType>, args: EmptyObject, options: O): void;
afterInit?(chart: Chart<TType>, args: EmptyObject, options: O): void;
// ...and so on
}Context
I've modified the options for the dataset for bar charts with TypeScript's declaration merging and I want to use this new highlightedColor property inside of the plugin without type errors. But plugin hooks have only a generic Chart interface without argument, so I can't use any custom dataset option inside to be typesafe.
declare module 'chart.js' {
interface BarControllerDatasetOptions {
highlightedColor: string;
}
}chart.js version
v4.2.1