Skip to content

Commit 9767620

Browse files
committed
fix: multitype charts typings
1 parent 5594170 commit 9767620

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

Diff for: src/types.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ import type {
1717
export interface Props<
1818
TType extends ChartType = ChartType,
1919
TData = DefaultDataPoint<TType>,
20-
TLabel = unknown,
21-
TOtherType extends TType = TType
20+
TLabel = unknown
2221
> extends CanvasHTMLAttributes<HTMLCanvasElement> {
2322
type: TType;
23+
/**
24+
* @todo Remove function variant.
25+
*/
2426
data:
25-
| ChartData<TOtherType, TData, TLabel>
26-
| ((canvas: HTMLCanvasElement) => ChartData<TOtherType, TData, TLabel>);
27-
options?: ChartOptions<TOtherType>;
28-
plugins?: Plugin<TOtherType>[];
27+
| ChartData<TType, TData, TLabel>
28+
| ((canvas: HTMLCanvasElement) => ChartData<TType, TData, TLabel>);
29+
options?: ChartOptions<TType>;
30+
plugins?: Plugin<TType>[];
2931
redraw?: boolean;
3032
/**
3133
* @todo Replace with `children` prop.
@@ -66,10 +68,9 @@ export type TypedChartComponent<
6668
: <
6769
TType extends ChartType = ChartType,
6870
TData = DefaultDataPoint<TType>,
69-
TLabel = unknown,
70-
TOtherType extends TType = TType
71+
TLabel = unknown
7172
>(
72-
props: Props<TType, TData, TLabel, TOtherType> & {
73+
props: Props<TType, TData, TLabel> & {
7374
ref?: ForwardedRef<ChartJSOrUndefined<TType, TData, TLabel>>;
7475
}
7576
) => JSX.Element;

Diff for: stories/Chart.data.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const multiTypeData = {
55
labels: months,
66
datasets: [
77
{
8-
type: 'line',
8+
type: 'line' as const,
99
label: 'Dataset 1',
1010
borderColor: colorRed,
1111
borderWidth: 2,
@@ -15,7 +15,7 @@ export const multiTypeData = {
1515
),
1616
},
1717
{
18-
type: 'bar',
18+
type: 'bar' as const,
1919
label: 'Dataset 2',
2020
backgroundColor: colorGreen,
2121
data: Array.from({ length: 7 }, () =>
@@ -25,7 +25,7 @@ export const multiTypeData = {
2525
borderWidth: 2,
2626
},
2727
{
28-
type: 'bar',
28+
type: 'bar' as const,
2929
label: 'Dataset 3',
3030
backgroundColor: colorBlue,
3131
data: Array.from({ length: 7 }, () =>

Diff for: test/chart.test-d.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { expectError } from 'tsd';
22
import React from 'react';
33
import { Plugin } from 'chart.js';
44
import Chart, { Scatter, Doughnut } from '../src';
5+
import { multiTypeData } from '../stories/Chart.data';
56

67
const data = {
78
datasets: [],
@@ -13,8 +14,9 @@ const data = {
1314

1415
<Chart type='radar' data={data} plugins={[] as Plugin<'radar'>[]} />;
1516
<Scatter data={data} plugins={[] as Plugin<'scatter'>[]} />;
17+
<Chart type='bar' data={multiTypeData} />;
18+
<Chart type='scatter' data={data} plugins={[] as Plugin<'bar'>[]} />;
1619

17-
expectError(<Chart type='radar' data={data} plugins={[] as Plugin<'bar'>[]} />);
1820
expectError(<Scatter data={data} plugins={[] as Plugin<'bar'>[]} />);
1921

2022
/**

0 commit comments

Comments
 (0)