Remove enum types (#7841)

* Remove type enum
* Add declare keyword to UpdateModeEnum
This commit is contained in:
emmcbd 2020-10-03 22:48:22 +02:00 committed by GitHub
parent 9b204eb278
commit d332ebc63d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 32 deletions

View 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']
}

View 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',

26
types/interfaces.d.ts vendored
View 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]
>;