Skip to content

Remove enum types #7841

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

Merged
merged 2 commits into from
Oct 3, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions docs/docs/developers/charts.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,14 @@ new Chart(ctx, {

If you want your new chart type to be statically typed, you must provide a `.d.ts` TypeScript declaration file. Chart.js provides a way to augment built-in types with user-defined ones, by using the concept of "declaration merging".

There are three main declarations that can be augmented when adding a new chart type:

* `ChartTypeEnum` enumeration must contain an entry for the new type.
* `IChartTypeRegistry` must contains the declarations for the new type, either by extending an existing entry in `IChartTypeRegistry` or by creating a new one.
When adding a new chart type, `IChartTypeRegistry` must contains the declarations for the new type, either by extending an existing entry in `IChartTypeRegistry` or by creating a new one.

For example, to provide typings for a new chart type that extends from a bubble chart, you would add a `.d.ts` containing:

```javascript
import { IChartTypeRegistry } from 'chart.js'

declare module 'chart.js' {
enum ChartTypeEnum {
derivedBubble = 'derivedBubble'
}

interface IChartTypeRegistry {
derivedBubble: IChartTypeRegistry['bubble']
}
Expand Down
2 changes: 1 addition & 1 deletion types/core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export declare type ChartItem =
| { canvas: HTMLCanvasElement | OffscreenCanvas }
| ArrayLike<CanvasRenderingContext2D | HTMLCanvasElement | OffscreenCanvas>;

export enum UpdateModeEnum {
export declare enum UpdateModeEnum {
resize = 'resize',
reset = 'reset',
none = 'none',
Expand Down
26 changes: 3 additions & 23 deletions types/interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,6 @@ export type DeepPartial<T> = T extends {}

export type DistributiveArray<T> = T extends unknown ? T[] : never

export enum ScaleTypeEnum {
linear = 'linear',
logarithmic = 'logarithmic',
category = 'category',
radialLinear = 'radialLinear',
time = 'time',
timeseries = 'timeseries',
}

export type IScaleType = keyof typeof ScaleTypeEnum;

export interface ICartesianScaleTypeRegistry {
linear: {
options: ILinearScaleOptions;
Expand Down Expand Up @@ -83,18 +72,7 @@ export interface IRadialScaleTypeRegistry {
export interface IScaleTypeRegistry extends ICartesianScaleTypeRegistry, IRadialScaleTypeRegistry {
}

export enum ChartTypeEnum {
bar = 'bar',
bubble = 'bubble',
doughnut = 'doughnut',
line = 'line',
pie = 'pie',
polarArea = 'polarArea',
radar = 'radar',
scatter = 'scatter',
}

export type IChartType = keyof typeof ChartTypeEnum;
export type IScaleType = keyof IScaleTypeRegistry;

export interface IChartTypeRegistry {
bar: {
Expand Down Expand Up @@ -147,6 +125,8 @@ export interface IChartTypeRegistry {
};
}

export type IChartType = keyof IChartTypeRegistry;

export type IScaleOptions<SCALES extends IScaleType = IScaleType> = DeepPartial<
{ [key in IScaleType]: { type: key } & IScaleTypeRegistry[key]['options'] }[SCALES]
>;
Expand Down