Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@
"include": [
"./src/**/*.js",
"./types"
],
"exclude": [
"./types/tests"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

types/tests removed from the config used by lint-tsc, because not all // @ts-except-error directives trigger without "strict: true" and the src folder gives a lot of errors with strict enabled.

types are tested with lint-types, using the config in types/tests:
"lint-types": "eslint \"types/**/*.ts\" && tsc -p types/tests/",

]
}
11 changes: 5 additions & 6 deletions types/index.esm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,14 +644,13 @@ export interface Defaults extends CoreChartOptions<ChartType>, ElementChartOptio
}

export type Overrides = {
[key in ChartType]: DeepPartial<
[key in ChartType]:
CoreChartOptions<key> &
ElementChartOptions &
PluginChartOptions<key> &
DatasetChartOptions<ChartType> &
ScaleChartOptions<key> &
ChartTypeRegistry[key]['chartOptions']
>;
ChartTypeRegistry[key]['chartOptions'];
}

export const defaults: Defaults;
Expand Down Expand Up @@ -2572,7 +2571,7 @@ export interface PluginOptionsByType<TType extends ChartType> {
tooltip: TooltipOptions<TType>;
}
export interface PluginChartOptions<TType extends ChartType> {
plugins: Partial<PluginOptionsByType<TType>>;
plugins: PluginOptionsByType<TType>;
}

export interface GridLineOptions {
Expand Down Expand Up @@ -3257,9 +3256,9 @@ export interface 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]
>;
;

export type DatasetChartOptions<TType extends ChartType = ChartType> = {
[key in TType]: {
Expand Down
18 changes: 18 additions & 0 deletions types/tests/plugins/defaults.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 32 additions & 0 deletions types/tests/scales/options.ts
Original file line number Diff line number Diff line change
@@ -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'
}
}
}
}
});
1 change: 1 addition & 0 deletions types/tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"target": "ES6",
"moduleResolution": "Node",
"alwaysStrict": true,
"strict": true,
"noEmit": true
},
"include": [
Expand Down
2 changes: 1 addition & 1 deletion types/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type DeepPartial<T> = T extends Function
type _DeepPartialArray<T> = Array<DeepPartial<T>>
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


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