Skip to content

Commit dee38b6

Browse files
authored
refactor: change types (#1132)
1 parent aa69514 commit dee38b6

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

src/chart.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useEffect, useRef, forwardRef } from 'react';
22
import { Chart as ChartJS } from 'chart.js';
33
import type { ChartType, DefaultDataPoint } from 'chart.js';
44

5-
import type { ForwardedRef, ChartProps, TypedChartComponent } from './types.js';
5+
import type { ForwardedRef, ChartProps, BaseChartComponent } from './types.js';
66
import {
77
reforwardRef,
88
cloneData,
@@ -107,6 +107,6 @@ function ChartComponent<
107107
);
108108
}
109109

110-
export const Chart: TypedChartComponent = forwardRef(
110+
export const Chart: BaseChartComponent = forwardRef(
111111
ChartComponent
112-
) as TypedChartComponent;
112+
) as BaseChartComponent;

src/typedCharts.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function createTypedChart<T extends ChartType>(
2727

2828
return forwardRef<ChartJSOrUndefined<T>, Omit<ChartProps<T>, 'type'>>(
2929
(props, ref) => <Chart {...props} ref={ref} type={type} />
30-
) as TypedChartComponent<T, true>;
30+
) as TypedChartComponent<T>;
3131
}
3232

3333
export const Line = /* #__PURE__ */ createTypedChart('line', LineController);

src/types.ts

+18-18
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,21 @@ export type ChartJSOrUndefined<
7373
TLabel = unknown
7474
> = Chart<TType, TData, TLabel> | undefined;
7575

76-
export type TypedChartComponent<
77-
TDefaultType extends ChartType = ChartType,
78-
TOmitType = false
79-
> = TOmitType extends true
80-
? <TData = DefaultDataPoint<TDefaultType>, TLabel = unknown>(
81-
props: Omit<ChartProps<TDefaultType, TData, TLabel>, 'type'> & {
82-
ref?: ForwardedRef<ChartJSOrUndefined<TDefaultType, TData, TLabel>>;
83-
}
84-
) => JSX.Element
85-
: <
86-
TType extends ChartType = ChartType,
87-
TData = DefaultDataPoint<TType>,
88-
TLabel = unknown
89-
>(
90-
props: ChartProps<TType, TData, TLabel> & {
91-
ref?: ForwardedRef<ChartJSOrUndefined<TType, TData, TLabel>>;
92-
}
93-
) => JSX.Element;
76+
export type BaseChartComponent = <
77+
TType extends ChartType = ChartType,
78+
TData = DefaultDataPoint<TType>,
79+
TLabel = unknown
80+
>(
81+
props: ChartProps<TType, TData, TLabel> & {
82+
ref?: ForwardedRef<ChartJSOrUndefined<TType, TData, TLabel>>;
83+
}
84+
) => JSX.Element;
85+
86+
export type TypedChartComponent<TDefaultType extends ChartType> = <
87+
TData = DefaultDataPoint<TDefaultType>,
88+
TLabel = unknown
89+
>(
90+
props: Omit<ChartProps<TDefaultType, TData, TLabel>, 'type'> & {
91+
ref?: ForwardedRef<ChartJSOrUndefined<TDefaultType, TData, TLabel>>;
92+
}
93+
) => JSX.Element;

0 commit comments

Comments
 (0)