mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-07 16:56:50 +01:00
Fix incomplete TS type for Chart.register + others (#9855)
This commit is contained in:
9
types/index.esm.d.ts
vendored
9
types/index.esm.d.ts
vendored
@@ -1060,7 +1060,7 @@ export interface Plugin<TType extends ChartType = ChartType, O = AnyObject> exte
|
||||
uninstall?(chart: Chart, args: EmptyObject, options: O): void;
|
||||
}
|
||||
|
||||
export declare type ChartComponentLike = ChartComponent | ChartComponent[] | { [key: string]: ChartComponent };
|
||||
export declare type ChartComponentLike = ChartComponent | ChartComponent[] | { [key: string]: ChartComponent } | Plugin | Plugin[];
|
||||
|
||||
/**
|
||||
* Please use the module's default export which provides a singleton instance
|
||||
@@ -1491,7 +1491,7 @@ export interface CoreChartOptions<TType extends ChartType> extends ParsingOption
|
||||
onClick(event: ChartEvent, elements: ActiveElement[], chart: Chart): void;
|
||||
|
||||
layout: {
|
||||
padding: Scriptable<number | ChartArea, ScriptableContext<TType>>;
|
||||
padding: Scriptable<number | Partial<ChartArea>, ScriptableContext<TType>>;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2538,6 +2538,11 @@ export interface TooltipOptions<TType extends ChartType = ChartType> extends Cor
|
||||
* @default 'rgba(0, 0, 0, 0.8)'
|
||||
*/
|
||||
backgroundColor: Scriptable<Color, ScriptableTooltipContext<TType>>;
|
||||
/**
|
||||
* Padding between the color box and the text.
|
||||
* @default 1
|
||||
*/
|
||||
boxPadding: number;
|
||||
/**
|
||||
* Color of title
|
||||
* @default '#fff'
|
||||
|
||||
@@ -20,3 +20,11 @@ Chart.defaults.font = {
|
||||
family: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
|
||||
size: 10
|
||||
};
|
||||
|
||||
Chart.defaults.layout = {
|
||||
padding: {
|
||||
bottom: 10,
|
||||
},
|
||||
};
|
||||
|
||||
Chart.defaults.plugins.tooltip.boxPadding = 3;
|
||||
|
||||
28
types/tests/extensions/plugin.ts
Normal file
28
types/tests/extensions/plugin.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Chart } from '../../index.esm';
|
||||
|
||||
Chart.register({
|
||||
id: 'my-plugin',
|
||||
afterDraw: (chart: Chart) => {
|
||||
// noop
|
||||
}
|
||||
});
|
||||
|
||||
Chart.register([{
|
||||
id: 'my-plugin',
|
||||
afterDraw: (chart: Chart) => {
|
||||
// noop
|
||||
},
|
||||
}]);
|
||||
|
||||
// @ts-expect-error not assignable
|
||||
Chart.register({
|
||||
id: 'fail',
|
||||
noComponentHasThisMethod: () => 'test'
|
||||
});
|
||||
|
||||
// @ts-expect-error missing id
|
||||
Chart.register([{
|
||||
afterDraw: (chart: Chart) => {
|
||||
// noop
|
||||
},
|
||||
}]);
|
||||
Reference in New Issue
Block a user