Fix incomplete TS type for Chart.register + others (#9855)

This commit is contained in:
Jukka Kurkela
2021-11-15 19:56:56 +02:00
committed by GitHub
parent 2988a6c6dc
commit e43730eb4d
3 changed files with 43 additions and 2 deletions

View File

@@ -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'

View File

@@ -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;

View 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
},
}]);