Skip to content

Commit

Permalink
Fix incomplete TS type for Chart.register + others (#9855)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Nov 15, 2021
1 parent 2988a6c commit e43730e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
9 changes: 7 additions & 2 deletions types/index.esm.d.ts
Expand Up @@ -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
Expand Down Expand Up @@ -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>>;
};
}

Expand Down Expand Up @@ -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'
Expand Down
8 changes: 8 additions & 0 deletions types/tests/defaults.ts
Expand Up @@ -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 changes: 28 additions & 0 deletions types/tests/extensions/plugin.ts
@@ -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
},
}]);

0 comments on commit e43730e

Please sign in to comment.