Skip to content

Commit e43730e

Browse files
authored
Fix incomplete TS type for Chart.register + others (#9855)
1 parent 2988a6c commit e43730e

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

types/index.esm.d.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ export interface Plugin<TType extends ChartType = ChartType, O = AnyObject> exte
10601060
uninstall?(chart: Chart, args: EmptyObject, options: O): void;
10611061
}
10621062

1063-
export declare type ChartComponentLike = ChartComponent | ChartComponent[] | { [key: string]: ChartComponent };
1063+
export declare type ChartComponentLike = ChartComponent | ChartComponent[] | { [key: string]: ChartComponent } | Plugin | Plugin[];
10641064

10651065
/**
10661066
* Please use the module's default export which provides a singleton instance
@@ -1491,7 +1491,7 @@ export interface CoreChartOptions<TType extends ChartType> extends ParsingOption
14911491
onClick(event: ChartEvent, elements: ActiveElement[], chart: Chart): void;
14921492

14931493
layout: {
1494-
padding: Scriptable<number | ChartArea, ScriptableContext<TType>>;
1494+
padding: Scriptable<number | Partial<ChartArea>, ScriptableContext<TType>>;
14951495
};
14961496
}
14971497

@@ -2538,6 +2538,11 @@ export interface TooltipOptions<TType extends ChartType = ChartType> extends Cor
25382538
* @default 'rgba(0, 0, 0, 0.8)'
25392539
*/
25402540
backgroundColor: Scriptable<Color, ScriptableTooltipContext<TType>>;
2541+
/**
2542+
* Padding between the color box and the text.
2543+
* @default 1
2544+
*/
2545+
boxPadding: number;
25412546
/**
25422547
* Color of title
25432548
* @default '#fff'

types/tests/defaults.ts

+8
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,11 @@ Chart.defaults.font = {
2020
family: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
2121
size: 10
2222
};
23+
24+
Chart.defaults.layout = {
25+
padding: {
26+
bottom: 10,
27+
},
28+
};
29+
30+
Chart.defaults.plugins.tooltip.boxPadding = 3;

types/tests/extensions/plugin.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Chart } from '../../index.esm';
2+
3+
Chart.register({
4+
id: 'my-plugin',
5+
afterDraw: (chart: Chart) => {
6+
// noop
7+
}
8+
});
9+
10+
Chart.register([{
11+
id: 'my-plugin',
12+
afterDraw: (chart: Chart) => {
13+
// noop
14+
},
15+
}]);
16+
17+
// @ts-expect-error not assignable
18+
Chart.register({
19+
id: 'fail',
20+
noComponentHasThisMethod: () => 'test'
21+
});
22+
23+
// @ts-expect-error missing id
24+
Chart.register([{
25+
afterDraw: (chart: Chart) => {
26+
// noop
27+
},
28+
}]);

0 commit comments

Comments
 (0)