Skip to content

Commit dd03016

Browse files
authored
Updates to scale type definitions (chartjs#11419)
While adding some type definitions to chartjs-plugin-zoom (see chartjs/chartjs-plugin-zoom#774), I noticed a few limitations in Chart.js's scale types: * The zoom plugin calls `Scale.parse` with no index parameter. Scale's JSDoc allows this, but its TypeScript definitions did not. * The zoom plugin alters scale options' min and max. The specific types of these depend on which scale is in use, but every scale has them, so `unknown` seems appropriate
1 parent e7b8164 commit dd03016

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/scales/scale.time.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function parse(scale, input) {
5656
value = parser(value);
5757
}
5858

59-
// Only parse if its not a timestamp already
59+
// Only parse if it's not a timestamp already
6060
if (!isFinite(value)) {
6161
value = typeof parser === 'string'
6262
? adapter.parse(value, /** @type {Unit} */ (parser))

src/types/index.d.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,22 @@ export interface CoreScaleOptions {
11761176
* @default true
11771177
*/
11781178
weight: number;
1179+
/**
1180+
* User defined minimum value for the scale, overrides minimum value from data.
1181+
*/
1182+
min: unknown;
1183+
/**
1184+
* User defined maximum value for the scale, overrides maximum value from data.
1185+
*/
1186+
max: unknown;
1187+
/**
1188+
* Adjustment used when calculating the maximum data value.
1189+
*/
1190+
suggestedMin: unknown;
1191+
/**
1192+
* Adjustment used when calculating the minimum data value.
1193+
*/
1194+
suggestedMax: unknown;
11791195
/**
11801196
* Callback called before the update process starts.
11811197
*/
@@ -1316,7 +1332,7 @@ export interface Scale<O extends CoreScaleOptions = CoreScaleOptions> extends El
13161332
getBasePixel(): number;
13171333

13181334
init(options: O): void;
1319-
parse(raw: unknown, index: number): unknown;
1335+
parse(raw: unknown, index?: number): unknown;
13201336
getUserBounds(): { min: number; max: number; minDefined: boolean; maxDefined: boolean };
13211337
getMinMax(canStack: boolean): { min: number; max: number };
13221338
getTicks(): Tick[];

0 commit comments

Comments
 (0)