mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 04:09:08 +02:00
Make type-tests strict (#8717)
This commit is contained in:
parent
3671c01c26
commit
499a71d4eb
@ -20,5 +20,8 @@
|
|||||||
"include": [
|
"include": [
|
||||||
"./src/**/*.js",
|
"./src/**/*.js",
|
||||||
"./types"
|
"./types"
|
||||||
|
],
|
||||||
|
"exclude": [
|
||||||
|
"./types/tests"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
11
types/index.esm.d.ts
vendored
11
types/index.esm.d.ts
vendored
@ -633,14 +633,13 @@ export interface Defaults extends CoreChartOptions<ChartType>, ElementChartOptio
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type Overrides = {
|
export type Overrides = {
|
||||||
[key in ChartType]: DeepPartial<
|
[key in ChartType]:
|
||||||
CoreChartOptions<key> &
|
CoreChartOptions<key> &
|
||||||
ElementChartOptions &
|
ElementChartOptions &
|
||||||
PluginChartOptions<key> &
|
PluginChartOptions<key> &
|
||||||
DatasetChartOptions<ChartType> &
|
DatasetChartOptions<ChartType> &
|
||||||
ScaleChartOptions<key> &
|
ScaleChartOptions<key> &
|
||||||
ChartTypeRegistry[key]['chartOptions']
|
ChartTypeRegistry[key]['chartOptions'];
|
||||||
>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defaults: Defaults;
|
export const defaults: Defaults;
|
||||||
@ -2561,7 +2560,7 @@ export interface PluginOptionsByType<TType extends ChartType> {
|
|||||||
tooltip: TooltipOptions<TType>;
|
tooltip: TooltipOptions<TType>;
|
||||||
}
|
}
|
||||||
export interface PluginChartOptions<TType extends ChartType> {
|
export interface PluginChartOptions<TType extends ChartType> {
|
||||||
plugins: Partial<PluginOptionsByType<TType>>;
|
plugins: PluginOptionsByType<TType>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GridLineOptions {
|
export interface GridLineOptions {
|
||||||
@ -3245,9 +3244,9 @@ export interface ChartTypeRegistry {
|
|||||||
|
|
||||||
export type ChartType = keyof ChartTypeRegistry;
|
export type ChartType = keyof ChartTypeRegistry;
|
||||||
|
|
||||||
export type ScaleOptionsByType<TScale extends ScaleType = ScaleType> = DeepPartial<
|
export type ScaleOptionsByType<TScale extends ScaleType = ScaleType> =
|
||||||
{ [key in ScaleType]: { type: key } & ScaleTypeRegistry[key]['options'] }[TScale]
|
{ [key in ScaleType]: { type: key } & ScaleTypeRegistry[key]['options'] }[TScale]
|
||||||
>;
|
;
|
||||||
|
|
||||||
export type DatasetChartOptions<TType extends ChartType = ChartType> = {
|
export type DatasetChartOptions<TType extends ChartType = ChartType> = {
|
||||||
[key in TType]: {
|
[key in TType]: {
|
||||||
|
18
types/tests/plugins/defaults.ts
Normal file
18
types/tests/plugins/defaults.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { defaults } from '../../index.esm';
|
||||||
|
|
||||||
|
// https://github.com/chartjs/Chart.js/issues/8711
|
||||||
|
const original = defaults.plugins.legend.labels.generateLabels;
|
||||||
|
|
||||||
|
defaults.plugins.legend.labels.generateLabels = function(chart) {
|
||||||
|
return [{
|
||||||
|
datasetIndex: 0,
|
||||||
|
text: 'test'
|
||||||
|
}];
|
||||||
|
};
|
||||||
|
|
||||||
|
// @ts-expect-error Type '{ text: string; }[]' is not assignable to type 'LegendItem[]'.
|
||||||
|
defaults.plugins.legend.labels.generateLabels = function(chart) {
|
||||||
|
return [{
|
||||||
|
text: 'test'
|
||||||
|
}];
|
||||||
|
};
|
32
types/tests/scales/options.ts
Normal file
32
types/tests/scales/options.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import { Chart } from '../../index.esm';
|
||||||
|
|
||||||
|
const chart = new Chart('test', {
|
||||||
|
type: 'bar',
|
||||||
|
data: {
|
||||||
|
labels: ['a'],
|
||||||
|
datasets: [{
|
||||||
|
data: [1],
|
||||||
|
}, {
|
||||||
|
type: 'line',
|
||||||
|
data: [{ x: 1, y: 1 }]
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
scales: {
|
||||||
|
x: {
|
||||||
|
type: 'time',
|
||||||
|
time: {
|
||||||
|
unit: 'year'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
x1: {
|
||||||
|
// @ts-expect-error Type '"linear"' is not assignable to type '"timeseries" | undefined'.
|
||||||
|
type: 'linear',
|
||||||
|
time: {
|
||||||
|
// @ts-expect-error Type 'string' is not assignable to type 'false | "millisecond" | "second" | "minute" | "hour" | "day" | "week" | "month" | "quarter" | "year" | undefined'.
|
||||||
|
unit: 'year'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
@ -3,6 +3,7 @@
|
|||||||
"target": "ES6",
|
"target": "ES6",
|
||||||
"moduleResolution": "Node",
|
"moduleResolution": "Node",
|
||||||
"alwaysStrict": true,
|
"alwaysStrict": true,
|
||||||
|
"strict": true,
|
||||||
"noEmit": true
|
"noEmit": true
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
|
2
types/utils.d.ts
vendored
2
types/utils.d.ts
vendored
@ -12,7 +12,7 @@ export type DeepPartial<T> = T extends Function
|
|||||||
type _DeepPartialArray<T> = Array<DeepPartial<T>>
|
type _DeepPartialArray<T> = Array<DeepPartial<T>>
|
||||||
type _DeepPartialObject<T> = { [P in keyof T]?: DeepPartial<T[P]> };
|
type _DeepPartialObject<T> = { [P in keyof T]?: DeepPartial<T[P]> };
|
||||||
|
|
||||||
export type DistributiveArray<T> = T extends unknown ? T[] : never
|
export type DistributiveArray<T> = [T] extends [unknown] ? Array<T> : never
|
||||||
|
|
||||||
// From https://stackoverflow.com/a/50375286
|
// From https://stackoverflow.com/a/50375286
|
||||||
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
||||||
|
Loading…
Reference in New Issue
Block a user