]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Remove enum types (#7841)
authoremmcbd <42184090+emmcbd@users.noreply.github.com>
Sat, 3 Oct 2020 20:48:22 +0000 (22:48 +0200)
committerGitHub <noreply@github.com>
Sat, 3 Oct 2020 20:48:22 +0000 (16:48 -0400)
* Remove type enum
* Add declare keyword to UpdateModeEnum

docs/docs/developers/charts.md
types/core/index.d.ts
types/interfaces.d.ts

index dfe8939dd0a406d374927672c1634303d231f186..1382ed09c74207f65d1bea380237b1a43fc434ef 100644 (file)
@@ -155,10 +155,7 @@ 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:
 
@@ -166,10 +163,6 @@ For example, to provide typings for a new chart type that extends from a bubble
 import { IChartTypeRegistry } from 'chart.js'
 
 declare module 'chart.js' {
-    enum ChartTypeEnum {
-        derivedBubble = 'derivedBubble'
-    }
-
     interface IChartTypeRegistry {
         derivedBubble: IChartTypeRegistry['bubble']
     }
index 4a00823d4a276bcf06ed09d34e134553c13e2ea3..dc3139dfa3412c73ff41e3ece2cb72402c362730 100644 (file)
@@ -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',
index 29a7e6bcd44d13da594766b5af3aec153edde131..dff4691e77a8d2dc995907832b197e478bf6a4c4 100644 (file)
@@ -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;
@@ -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: {
@@ -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]
 >;