Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
},
}]);