Skip to content

Commit 537064b

Browse files
authored
Modify Scale typing (#8681)
1 parent 375d856 commit 537064b

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

types/index.esm.d.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,10 +1260,9 @@ export interface Scale<O extends CoreScaleOptions = CoreScaleOptions> extends El
12601260

12611261
isFullSize(): boolean;
12621262
}
1263-
export const Scale: {
1264-
prototype: Scale;
1265-
new <O extends CoreScaleOptions = CoreScaleOptions>(cfg: AnyObject): Scale<O>;
1266-
};
1263+
export declare class Scale {
1264+
constructor(cfg: {id: string, type: string, ctx: CanvasRenderingContext2D, chart: Chart});
1265+
}
12671266

12681267
export interface ScriptableScaleContext {
12691268
chart: Chart;

types/tests/extensions/scale.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { AnyObject } from '../../basic';
2+
import { CartesianScaleOptions, Chart, Scale } from '../../index.esm';
3+
4+
export type TestScaleOptions = CartesianScaleOptions & {
5+
testOption?: boolean
6+
}
7+
8+
export class TestScale<O extends TestScaleOptions = TestScaleOptions> extends Scale<O> {
9+
static id: 'test';
10+
11+
getBasePixel(): number {
12+
return 0;
13+
}
14+
15+
testMethod(): void {
16+
//
17+
}
18+
}
19+
20+
declare module '../../index.esm' {
21+
interface CartesianScaleTypeRegistry {
22+
test: {
23+
options: TestScaleOptions
24+
}
25+
}
26+
}
27+
28+
29+
Chart.register(TestScale);
30+
31+
const chart = new Chart('id', {
32+
type: 'line',
33+
data: {
34+
datasets: []
35+
},
36+
options: {
37+
scales: {
38+
x: {
39+
type: 'test',
40+
position: 'bottom',
41+
testOption: true,
42+
min: 0
43+
}
44+
}
45+
}
46+
});
47+
48+
Chart.unregister([TestScale]);

0 commit comments

Comments
 (0)