Skip to content

Commit 217f44b

Browse files
committed
Make type-tests strict
1 parent 9583edd commit 217f44b

File tree

6 files changed

+60
-7
lines changed

6 files changed

+60
-7
lines changed

tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,8 @@
2020
"include": [
2121
"./src/**/*.js",
2222
"./types"
23+
],
24+
"exclude": [
25+
"./types/tests"
2326
]
2427
}

types/index.esm.d.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -644,14 +644,13 @@ export interface Defaults extends CoreChartOptions<ChartType>, ElementChartOptio
644644
}
645645

646646
export type Overrides = {
647-
[key in ChartType]: DeepPartial<
647+
[key in ChartType]:
648648
CoreChartOptions<key> &
649649
ElementChartOptions &
650650
PluginChartOptions<key> &
651651
DatasetChartOptions<ChartType> &
652652
ScaleChartOptions<key> &
653-
ChartTypeRegistry[key]['chartOptions']
654-
>;
653+
ChartTypeRegistry[key]['chartOptions'];
655654
}
656655

657656
export const defaults: Defaults;
@@ -2572,7 +2571,7 @@ export interface PluginOptionsByType<TType extends ChartType> {
25722571
tooltip: TooltipOptions<TType>;
25732572
}
25742573
export interface PluginChartOptions<TType extends ChartType> {
2575-
plugins: Partial<PluginOptionsByType<TType>>;
2574+
plugins: PluginOptionsByType<TType>;
25762575
}
25772576

25782577
export interface GridLineOptions {
@@ -3257,9 +3256,9 @@ export interface ChartTypeRegistry {
32573256

32583257
export type ChartType = keyof ChartTypeRegistry;
32593258

3260-
export type ScaleOptionsByType<TScale extends ScaleType = ScaleType> = DeepPartial<
3259+
export type ScaleOptionsByType<TScale extends ScaleType = ScaleType> =
32613260
{ [key in ScaleType]: { type: key } & ScaleTypeRegistry[key]['options'] }[TScale]
3262-
>;
3261+
;
32633262

32643263
export type DatasetChartOptions<TType extends ChartType = ChartType> = {
32653264
[key in TType]: {

types/tests/plugins/defaults.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { defaults } from '../../index.esm';
2+
3+
// https://github.com/chartjs/Chart.js/issues/8711
4+
const original = defaults.plugins.legend.labels.generateLabels;
5+
6+
defaults.plugins.legend.labels.generateLabels = function(chart) {
7+
return [{
8+
datasetIndex: 0,
9+
text: 'test'
10+
}];
11+
};
12+
13+
// @ts-expect-error Type '{ text: string; }[]' is not assignable to type 'LegendItem[]'.
14+
defaults.plugins.legend.labels.generateLabels = function(chart) {
15+
return [{
16+
text: 'test'
17+
}];
18+
};

types/tests/scales/options.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { Chart } from '../../index.esm';
2+
3+
const chart = new Chart('test', {
4+
type: 'bar',
5+
data: {
6+
labels: ['a'],
7+
datasets: [{
8+
data: [1],
9+
}, {
10+
type: 'line',
11+
data: [{ x: 1, y: 1 }]
12+
}]
13+
},
14+
options: {
15+
scales: {
16+
x: {
17+
type: 'time',
18+
time: {
19+
unit: 'year'
20+
}
21+
},
22+
x1: {
23+
// @ts-expect-error Type '"linear"' is not assignable to type '"timeseries" | undefined'.
24+
type: 'linear',
25+
time: {
26+
// @ts-expect-error Type 'string' is not assignable to type 'false | "millisecond" | "second" | "minute" | "hour" | "day" | "week" | "month" | "quarter" | "year" | undefined'.
27+
unit: 'year'
28+
}
29+
}
30+
}
31+
}
32+
});

types/tests/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"target": "ES6",
44
"moduleResolution": "Node",
55
"alwaysStrict": true,
6+
"strict": true,
67
"noEmit": true
78
},
89
"include": [

types/utils.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export type DeepPartial<T> = T extends Function
1212
type _DeepPartialArray<T> = Array<DeepPartial<T>>
1313
type _DeepPartialObject<T> = { [P in keyof T]?: DeepPartial<T[P]> };
1414

15-
export type DistributiveArray<T> = T extends unknown ? T[] : never
15+
export type DistributiveArray<T> = [T] extends [unknown] ? Array<T> : never
1616

1717
// From https://stackoverflow.com/a/50375286
1818
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;

0 commit comments

Comments
 (0)