From d332ebc63d46e4cc7657662cc47835ec94f5b52d Mon Sep 17 00:00:00 2001 From: emmcbd <42184090+emmcbd@users.noreply.github.com> Date: Sat, 3 Oct 2020 22:48:22 +0200 Subject: [PATCH] Remove enum types (#7841) * Remove type enum * Add declare keyword to UpdateModeEnum --- docs/docs/developers/charts.md | 9 +-------- types/core/index.d.ts | 2 +- types/interfaces.d.ts | 26 +++----------------------- 3 files changed, 5 insertions(+), 32 deletions(-) diff --git a/docs/docs/developers/charts.md b/docs/docs/developers/charts.md index dfe8939dd..1382ed09c 100644 --- a/docs/docs/developers/charts.md +++ b/docs/docs/developers/charts.md @@ -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'] } diff --git a/types/core/index.d.ts b/types/core/index.d.ts index 4a00823d4..dc3139dfa 100644 --- a/types/core/index.d.ts +++ b/types/core/index.d.ts @@ -315,7 +315,7 @@ export declare type ChartItem = | { canvas: HTMLCanvasElement | OffscreenCanvas } | ArrayLike; -export enum UpdateModeEnum { +export declare enum UpdateModeEnum { resize = 'resize', reset = 'reset', none = 'none', diff --git a/types/interfaces.d.ts b/types/interfaces.d.ts index 29a7e6bcd..dff4691e7 100644 --- a/types/interfaces.d.ts +++ b/types/interfaces.d.ts @@ -45,17 +45,6 @@ export type DeepPartial = T extends {} export type DistributiveArray = 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 = DeepPartial< { [key in IScaleType]: { type: key } & IScaleTypeRegistry[key]['options'] }[SCALES] >; -- 2.47.2